Support the ongoing development of Laravel.io →
Authentication Eloquent Validation
Last updated 1 year ago.
0

please share ur table structures.

0

Thanks for your reply, here are my tables:

users

Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password', 60);
        $table->rememberToken();
        $table->timestamps();
});

###patients

Schema::create('patients', function (Blueprint $table) {
        $table->increments('id');
        //Foreign key
        $table->integer('user_id')->unsigned();

        $table->string('ci')->unique();
        $table->string('name');
        $table->string('last_name');
        $table->string('gender');        
        $table->timestamps();
        $table->softDeletes();

        $table->foreign('user_id')
                 ->references('id')->on('users');
});

I should add that when I process a patient creation using tinker, the record is properly saved in the database. And it works as well when I fetch the user's patients as follows:

>>>$user = App\User::first();
>>>$user->patients()->get();
=> => Illuminate\Database\Eloquent\Collection {#677
     all: [
       App\Patient {#691
         id: "1",
         user_id: "1",
         ci: "123456789",
         name: "John",
         last_name: "Smith",
         gender: "Male"
         created_at: "2016-04-26 00:12:49",
         updated_at: "2016-04-26 00:12:49",
         deleted_at: null,
       },
     ],
   }
Last updated 7 years ago.
0
Solution

SOLVED, the problem was that I left uncommented both option in the providers array inside the auth.php file

'providers' => [
        'users' => [
                'driver' => 'eloquent',
                'model' => App\User::class,
        ],
        
        // ERROR
        // Call to undefined method Illuminate\Auth\GenericUser::patients()

        // 'users' => [
                //'driver' => 'database',
                //'table' => 'users',
        // ],
],
Last updated 7 years ago.
0

Hey @Veuge! Thank you very much! it was very helpful!!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Veuge veuge Joined 20 Apr 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.