mardi 19 janvier 2016

Sorting a polymorphic relationship laravel

I have currently set up a poloymorphic relationship by using a views table to represent this and it is working

Whenever I try something like this:

    public function index($id)
    {
        $bar = Bar::find($id);

        echo count($bar->views);
    }

I get the number of results I am expecting and the results are properly viewable with a var_dump as well.

Only when I try to sort the results with a simply where statement like this, I am getting no results at all. I tried multiple where statements but simply nothing happens. No errors.

   public function index($id)
    {
        $bar = Bar::find($id);

        $bar->views->where('id', '=', 1);
    }

Can I not sort the results that I have gotten returned from the polymorphic relationship or I something else going wrong here?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire