Thanks for your reply, here are my tables:
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,
},
],
}
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',
// ],
],
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community