Praleisti ir pereiti prie pagrindinio turinio

Pranešimai

Rodomi įrašai nuo gegužė, 2018

Laravel: request duomenų įrašymas į db

/app/Http/Controllers/PostController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Post; class PostController extends Controller {     public function create(Request $request, Post $post ){     //gautą post žinutę įrašome į duomenų bazę     $createdPost = $request->user()->posts()->create([     'body' => $request->body     ]);     //gražiname atsakymą json formate     return response()->json($post->with('user')->find($createdPost->id));     } } Rezultatas:

Laravel: React axios post request

https://github.com/axios/axios Įdiegiame axios į React: npm install axios /resources/aaets/js/components/App/js import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import axios from 'axios'; class App extends Component {     constructor(props){         super(props);         this.state ={              body:''         }         // bind          this.handleSubmit = this.handleSubmit.bind(this);         this.handleChange = this.handleChange.bind(this);     }        handleSubmit(e){        e.preventDefault(); //stop refresh after submit        this.postData();        console.log(this.state.body);     }       postData(){         a...

Laravel: model, migration, relationship

Sukuriame modelį Post: php artisan make:model Post -m Turime migracijos failą database/migrations/data_create_posts_table.php <?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreatePostsTable extends Migration {     /**      * Run the migrations.      *      * @return void      */     public function up()     {         Schema::create('posts', function (Blueprint $table) {             $table->increments('id');             $table->timestamps();         });     }     /**      * Reverse the migrations.      *      * @return void      */     public function down()     { ...

Laravel: Boostrap form

Apso forma resources/assets/js/components/App.js: import React, { Component } from 'react'; import ReactDOM from 'react-dom'; class App extends Component {  render() {   return (    <div className="container">      <div className="row justify-content-center">       <div className="col-md-6">        <div className="card">          <div className="card-header">Tweet something</div>           <div className="card-body">             <form>             <div className="form-group">              <textarea                className="form-control"                rows="5"                maxleng...

Laravel: React komponentai

React komponento integracija laravel  framework'e Turime blade pagrindinį views: resources/views/layouts/app.blade.php : <!DOCTYPE html> .... integruojame musu appsą  <!-- Scripts -->   <script src="{{ asset('js/app.js') }}" defer></script> ....  </head> <body> ....ir žamiau turime yield         <main class="py-4">             @yield('content')         </main>  </div> </body> </html> Krauname mūdų view resources/views/home.blade.php kuris 'praplečia' aukščiau esantį app.blade.php yielde užkraudamas kontentą: @extends('layouts.app') @section('content') <div class="container">     <div id="root"></div> </div > @endsection kontentas yra div su id root. Į jį rendinsismusu appsas. resources/assets/js/app.js : .... require('./components/ index '); ...

Laravel: And React preset

React prijungimas prie laravel projekto: php artisan preset react toliau naudodamiesi npm diegime react: npm install && npm run dev Pastovus pokyčių sekimas: rpm run watch Rezultate resources/assets/js/components/example.js: randasi sugeneruotas pavizdinis React komponentas: Šį komponentą iškviečia app.js: welcome šablonas atrodo taip: <!doctype html> <html lang="{{ app()->getLocale() }}">    <head>  ...     <link href="{{asset('css/app.css')}}" rel="stylesheet" type="text/css">  ...  </head>  <body>         <div id="container" class="mt-30">      <div id="example"></div>      <script src="{{asset('js/app.js')}}" ></script>    </div>            </body> </html> Pvz:

Laravel: migrate

Duomenų bazės lentelių sukūrimui naudojame komanda: php artisan migrate Rezultate bus sukurtos lentelės aprašytos migracijos failuose: Jei gauname klaida:   Illuminate\Database\QueryException  : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))   at D:\wamp64\www\lareact\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664     660|         // If an exception occurs when attempting to run a query, we'll format the error     661|         // message to include the bindings with SQL, which will make this exception a     662|         // lot more helpful to the developer instead of just the database's errors.     663|         catch (Exception $e) {   > 664|    ...

Laravel: controleris

Kontrolerio sukurimas: php artisan make:controller TimelineController Po šios komandos bus sukurtas TimelineController.php kataloge: app\Http\Controllers. Šis kontroleris kontroliuos mūsų 'linkus'. Toliau keičiame routes/web.php: <?php Auth::routes(); Route::group(['middleware' => ['auth']], function(){ Route::get('/', ' TimelineController@index '); }); Toliu aprašome metodą index į kurį kreipsimės: <?php namespace App\Http\Controllers; use Illuminate\Http\Request; class TimelineController extends Controller {     public function index (){     return view(' home ');     } } Ir turime tik prisijungus pasiekiamą aplinką...

Laravel: name -> username

Keičiame Name į Username: resources/views/auth/register.blade.php : ... <div class="form-group row">  <label for=" username " class="col-md-4 col-form-label text-md-right">{{ __(' Username ') }}</label>  <div class="col-md-6">   <input id=" username " type="text" class="form-control{{ $errors->has(' username ') ? ' is-invalid' : '' }}" name=" username " value="{{ old(' username ') }}" required autofocus>   @if ($errors->has(' username '))    <span class="invalid-feedback">     <strong>{{ $errors->first(' username ') }}</strong>    </span>   @endif  </div> </div> ... resources/views/layouts/app.blade.php : 49 eilte ...  {{ Auth::user()-> username }} <span class="caret"></span> ... app/Http/Controllers/Aut...

Laravel: auth diegimas

Laravel auth (login registracijos funkcionalumo diegimas): php artisan make:auth

Laravel: prisijungimas prie mysql

Prisijungimo parametrus nurodome projekto šakniniame kataloge .env faile:

Disabling SkypeBrowserHost

https://www.reddit.com/r/skype/comments/6a2pmz/howto_disabling_skypebrowserhost/ [How-To] Disabling SkypeBrowserHost Noticed that there's a process called SkypeBrowserHost.exe running, taking up a lot more CPU resources than it should? You're not the only one, and the program does  virtually nothing  and can be safely disabled. Despite what's listed about deleting or renaming the file in the link above, that is no longer an option as Skype will fail to launch correctly. Here's a workaround that I found. Close Skype if it is already running Create and open a text file with Notepad on your desktop (or anywhere else) Leave it's content blank, then go to  Save As , change  Save as type  to  All files (*.*)  and then save it as  SkypeBrowserHost.exe . Go to  C:\Program Files (x86)\Skype\Browser , delete the pre-exising SkypeBrowserHost.exe and move in the one you just created. This will serve as a dummy executable t...

Laravel: pradžia [pasiruošimas]

Įsidiegiame composer : https://getcomposer.org/ Diegiame laravel į composer globaliai... : https://laravel.com/docs/5.6#installation composer global require "laravel/installer" tada sukuriame laravel projektą [sukurs katalogą blog ir jame įdiegs laravel]: laravel new blog arba: composer create-project --prefer-dist laravel/laravel blog

React: event, destructor, inline style, key, join

Kodo pavyzdys [naudojant axios ] gautų duomenų talpinimas į State. Pridėtas evant'as, reguojantis į paspaudimą. Naudojimo inline style pavyzdys. Masyvų sujungimas, siekiant neprarasti jau turimų state duomenų. Bindinimas. Pasikartojantiems elementams key suteikimas - nes visi React elementai turi turėti savo unikalius numerius, todėl pasikartojančius reikia papildomai juos 'išskirti'.    //App.js import React, { Component } from 'react'; import axios from 'axios' import Loading from './Loading'

React: axios to state

Naudosime api [ https://api.randomuser.me/?nat=US&results=5 ] serverio vaidmeniui import React, { Component } from 'react'; import axios from 'axios' class App extends Component {   constructor(props){     super(props)     //state     this.state ={       users: []     }   }

React: create-react-app

node turi būti įdiegtas:  https://nodejs.org/en/ aprašymas: https://reactjs.org/tutorial/tutorial.html komandos: glolabus diegimas: npm install -g create-react-app react app'so sukurimas (my-app - pavadinimas): create-react-app my-app axios diegimas [ https://www.npmjs.com/package/axios ]: npm install axios Bootstrap diegimas į react: npm install --save bootstrap reactstrap@next Importuojame į src/index.js: import 'bootstrap/dist/css/bootstrap.css';

ES6: classes constructor and super

Klasės sukūrimas: class Holiday{} console.log(Holiday.prototype); Rezultatas:

ES6: prototype

ES6 prototipai: function Holiday(destination, days){ this.destination = destination; this.days = days; } Holiday. prototype. info = function(){ console.log(this.destination + ' | ' + this.days + ' days'); }; var Nepal = new Holiday('Nepal', 30); console.log(Nepal.info());