User::create() results No query results for model [App\User].
I run the following method and for some reason, it makes the table, but then right after it throws an error.
public function create_user(){
$user = User::create([
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'email' => $this->email,
'password' => bcrypt($this->password)
]);
}
error:
No query results for model [App\User].
This doesn't make any sense to me; I'm not even looking for results.
Any ideas?
Where do you call this method? Do you redirect to a certain route or view after creating this user?
Can you show the code where you call the create_user method?
@BOBBYBOUWMANN -
where create_user() is being called
public function register(){
try{
$this->create_user();
return $this->token();
}catch(Exception $e){
return $e->getMessage();
}
}
/**
* return login token
*/
public function token(){
$token = $this->user->createToken('login')->accessToken;
return response()->json(['token' => $token], 200);
}
In another file, I call this class
public function register(RegVal $request){
try{
$register = new Register($request->first_name,
$request->last_name, $request->email, $request->password);
return $register->register();
}catch(Exception $e){
return $e->getMessage();
}
}
Do you assign the created user (in create_user()?) to $this->user somewhere, I cannot see it??
@TYKUS - Yes, I did. Also i tried running this code in a simple routes file:
Route::get('/test', function () {
$user = User::create([
'first_name' => 'Jake',
'last_name' => 'Paul',
'email' => '[email protected]',
'password' => bcrypt('hshshsh')
]);
});
And I get the same error
No query results for model [App\User].
Super weird
Are you trying to query for a User somewhere else as the app is bootstrapping, e.g. in a ServiceProvider, or in a Middleware?
@TYKUS - Hmmm, that has to be it. I'm just not sure where on earth this would be happening. Any ideas on where to look for this query?
Laravel Debugbar or Laravel Telescope will tell you where queries are being executed.
No query results for model [App\User]
This error should give you a file, line number and stack trace?
Please or to participate in this conversation.