mardi 26 septembre 2017

Use class of related model in laravel

I'm trying to use class name of related model in laravel eloquent method by using "USE" for giving aliases to names of model classes. For example, I have used UserProfile model class:

namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\UserProfile;

And now I am using it in eloquent as follow:

public function profileDetails() {
    return $this->hasOne('UserProfile', 'user_id', 'id');
}

But this throws an error of Class 'UserProfile' not found And If I directly pass name of the related model with path in first argument of this eloquent, then it's working fine

public function profileDetails() {
    return $this->hasOne('App\Models\UserProfile', 'user_id', 'id');
}

I'm wondering why it's not working with use



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire