【发布时间】:2016-01-15 00:06:21
【问题描述】:
在laravel我有以下2个模型;
这是parent
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RestaurantClass extends Model
{
/**
* Get the restaurants for the restaurant class.
*/
public function restaurants()
{
return $this->hasMany('App\Models\Restaurant');
}
}
这是child;
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Restaurant extends Model
{
/**
* Get the restaurant class that owns the restaurant.
*/
public function restaurantClass()
{
return $this->belongsTo('App\Models\RestaurantClass');
}
}
如何检索孩子及其父母,反之亦然(检索父母及其所有孩子)
任何指导表示赞赏。
【问题讨论】:
标签: laravel laravel-5 eloquent