Wednesday, March 8, 2017

hasMany Relation Laravel - Not getting query result

I have a post with multiple images. But I want to only fetch images with PNG format. So I do this is post :

 public function images() {
        return $this->hasMany('App\ImagesModel','mapID','id');
    }

    public function oftype($query)
    {
        return
        $query->where('type', '=', 'PNG');
    }

But this is not working.

$post = Post::find($id);
$post->images()->oftype()->get();

Kindly help.



via kirobo

Advertisement