dimanche 24 février 2019

Laravel 5 Auth::id() returns NULL in UserFactory.php

i want to store my authenticated user id in one of my tables.In my UserFactory.php i write

$factory->define(App\Programming::class, function (Faker $faker) {
return [

    'name' => $faker->name,
    'user_id'=>Auth::id(),

];});

I am logged in and use Illuminate\Support\Facades\Auth is also included at the top.I get the following error while seeding my data

Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'user_id' cannot be null.

Any Solution?Thanks in advance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire