As i use User::findOrFail();
it's gives me method findOrFail not found in usr model
at the User Model :-
i tried -> use Illuminate\Database\Eloquent\Builder;
but no hope i see it in the documentation then it suppose still working..
namespace App;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function address()
{
return $this->hasMany('App\Address');
}
}
I am New in laravel and in the first stages so i can't use Exception stack trace in the moment so am using Phpstorm and i got the error when i get my arrow to the findOrFail()
it gives me this message -> " method 'findOrFail' not found in App\User
Referenced Method is not found in the subject class ".
@snapey I think he means his IDE (phpstorm) reports the findOrFail method is not found, not that it won't work if executed.
@Viernes Laravel uses lots of magic behind the scenes that a lot of IDE's can't pick up on.
In phpstorm, make sure you have the laravel plugin installed and enabled. Also, this package will help phpstorm find a lot of the magic that the IDE can't figure out: https://github.com/barryvdh/laravel-ide-helper
@Cronix Thanks man it's works now after the installation of the package you mentioned and your theory very true the code works fine even if it's show an error in (Phpstorm) as you said "Laravel uses lots of magic behind the scenes that a lot of IDE's can't pick up on.".
Thanks Again (Y)
I know this is an old post but I want to provide the answer. Since this issue shows on PhpStorm you have to run the Generate Helper Code on the Laravel menu on PhpStorm. It will build the helper classes that the current project needs to ensure that we don't get these kind of errors.
After running this, the errors will automatically hide, in this case for the findOrFail.
Hello guys, today I woke up wondering: "Why doesn’t PhpStorm recognize some model static functions?"
I searched a bit on the internet and found out! You just need to download the Laravel Idea plugin (currently free), go to Languages & Frameworks > Laravel Idea > Eloquent, check the option "Implicit Eloquent method usages searcher (might use a lot of CPU resources)", and apply.