samedi 2 janvier 2016

\Laravel hasMany method not working

I have 2 tables, users and websites. One user can have multiple websites assigned to it.

public function websites() {
    return $this->hasMany('App\Models\Website');
}

The error I get is:

Object of class Illuminate\Database\Eloquent\Relations\HasMany could not be converted to string

If I try to output it as an array using print_r I get hundreds of lines of array which I'm assuming is caused by an error somewhere.

Also, why do I have to use App\Models\Website in the hasMany method if I specified at the top of User model use App\Models\Website;?

If I use just Website in the method, I get class not found error:

Class 'Website' not found

Not a big deal, but it would be much cleaner not to have to use the full namespace path.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire