mercredi 2 septembre 2015

Laravel 5 belongsToMany how to get the data in the method all();

i used to belongsToMany relationship i tried my Resta model

public function kitchens()
{
    return $this->belongsToMany('App\Kitchen')->withTimestamps();
}

my Kitchen model

public function resto()
{
    return $this->belongsToMany('App\Resto');
}

function for return Resto data

public function getAllRest($city)
{
    $restos = Resto::latest('created_at')
        ->where('city','=', $city)
        ->get();

    return $restos;
}

Now when I have an interface relations, as they output? In one I know that it is possible to do so

 $resta = Resto::find($id);
 $resta->kitchens->toArray();

How can I output in the derivation of all the data?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1NayOsX
via IFTTT

Aucun commentaire:

Enregistrer un commentaire