I'm using Laravel 5 and have multiple models (Patient, Therapist) that extend from User model.
I have some dummy data in the DB (few therapists, few patients).
When I want to retrieve a therapist by id, I try to do so by Therapist::find($id) but get an exception:
'Illuminate\Database\QueryException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'users_email_unique' (SQL: insert into users
Couple of questions:
1. Why when I use the ::find function, it tries to insert a new user?
2. How can I use the ::find function on objects that extend from User in order to get the attributes that each model has?
EDIT:
Code that creates the error: $user = Therapist::find(13);
Full exception:
Next exception 'Illuminate\Database\QueryException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'users_email_unique' (SQL: insert intousers(updated_at,created_at) values (2016-07-24 12:33:06, 2016-07-24 12:33:06))' in C:\wamp\www\clinic\vendor\laravel\framework\src\Illuminate\Database\Connection.php:725 Stack trace: C:\wamp\www\clinic\vendor\laravel\framework\src\Illuminate\Database\Connection.php(681): Illuminate\Database\Connection->runQueryCallback('insert intous...', Array, Object(Closure)) C:\wamp\www\clinic\vendor\laravel\framework\src\Illuminate\Database\Connection.php(454): Illuminate\Database\Connection->run('insert into us...', Array, Object(Closure)) C:\wamp\www\clinic\vendor\laravel\framework\src\Illuminate\Database\Connection.php(410): Illuminate\Database\Connection->statement('insert intous...', Array)`
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2alIFRb
via IFTTT
Aucun commentaire:
Enregistrer un commentaire