Laravel 5.3 withCount() nested relation

You can only do a withCount() on a defined relation of the model. However, a relationship can be hasManyThrough which would achieve what you are after. class Tutorial extends Model { function chapters() { return $this->hasMany(‘App\Chapter’); } function videos() { return $this->hasManyThrough(‘App\Video’, ‘App\Chapter’); } } And then you can do: Tutorial::withCount([‘chapters’, ‘videos’]) Docs: https://laravel.com/docs/5.3/eloquent-relationships#has-many-through

Laravel 5.3 – How to add Sessions to `API` without CSRF?

go to app/Http/Kernel.php and add your own name like ‘sessions’ to the $middlewareGroups. It should contain \Illuminate\Session\Middleware\StartSession::class, Assign ‘sessions’ to those routes you want. protected $middlewareGroups = [ ‘web’ => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, ], ‘api’ => [ ‘throttle:60,1’, ], ‘sessions’ => [ \Illuminate\Session\Middleware\StartSession::class, ] ]; routes/api.php Route::group([‘middleware’ => [‘sessions’]], function () { … Read more

Error Field doesn’t have a default value in laravel 5.3

You should add ->nullable() or ->default(‘somethingHere’) to fields which you send empty values. $table->string(‘family’)->nullable(); //this means that if you send empty value this field will become MySQL NULL Or set default value: $table->string(‘family’)->default(‘default value here’); Than remigrate: php artisan migrate:rollback and php artisan migrate

Is it possible to change props value from method in Vue component?

What you are doing will throw a warning in Vue (in the console). [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop’s value. Prop being mutated: “propRoomSelected” The value will actually change inside the component, … Read more

laravel 5.3 new Auth::routes()

Auth::routes() is just a helper class that helps you generate all the routes required for user authentication. You can browse the code here https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php instead. Here are the routes // Authentication Routes… $this->get(‘login’, ‘Auth\LoginController@showLoginForm’)->name(‘login’); $this->post(‘login’, ‘Auth\LoginController@login’); $this->post(‘logout’, ‘Auth\LoginController@logout’)->name(‘logout’); // Registration Routes… $this->get(‘register’, ‘Auth\RegisterController@showRegistrationForm’)->name(‘register’); $this->post(‘register’, ‘Auth\RegisterController@register’); // Password Reset Routes… $this->get(‘password/reset’, ‘Auth\ForgotPasswordController@showLinkRequestForm’); $this->post(‘password/email’, ‘Auth\ForgotPasswordController@sendResetLinkEmail’); $this->get(‘password/reset/{token}’, ‘Auth\ResetPasswordController@showResetForm’); … Read more

Laravel’s 5.3 passport and api routes

The problem with Laravel 5.3 passport is that unlike previous OAuth 2.0 Server for Laravel library offered by lucadegasperi, it has no API to make clients directly. So as if now the client can only be made through the front-end. FYI we wanted to use laravel passport solely for our mobile app so while creating … Read more

How to pass laravel CSRF token value to vue

Very Easy Solution Just add a hidden field inside the form. An Example <form id=”logout-form” action=”/logout” method=”POST” style=”display: none;”> <input type=”hidden” name=”_token” :value=”csrf”> </form> Now add csrf variable inside script at the vue file, like this. (Remember, it must be inside data). <script> export default { data: () => ({ csrf: document.querySelector(‘meta[name=”csrf-token”]’).getAttribute(‘content’), }), } </script> … Read more