mardi 31 juillet 2018

Query hasMany relation with slug instead of id?

I'm trying to query a category and all of its channels based on a slug.

Works

\App\Category::find(1)->channels()->get();

Doesn't Work

\App\Category::where('slug','animals')->channels()->get()

BadMethodCallException with message 'Method Illuminate/Database/Query/Builder::channels does not exist.'

Relationship on Category Model

public function channels()
{
    return $this->hasMany(Channel::class,'category_id');
}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2AwrY20
via IFTTT

Aucun commentaire:

Enregistrer un commentaire