0

このようなことをしたいと思います。

Location::where('city', '=', 'Chicago')->chef();

これらの関係で:

class Location extends Eloquent {
    protected $table = 'locations';

    public function chef() {
        return $this->belongsTo('Chef');
    }
}

class Chef extends Eloquent {
    protected $table = 'chefs';

    public function location() {
        return $this->hasMany('Location');
    }
}
4

1 に答える 1

2

これはうまくいくはずです:

class Location extends Eloquent {
    protected $table = 'locations';

    public function chefs() {
        return $this->belongsTo('Chef');
    }

    public function getAllChefsByCity($city)
    {
         $this->with('chefs')->where('city', $city)->get();
    }
}

次に、コードで:

$array = $location->getAllChefsByCity('Chicago');
于 2013-07-07T23:38:58.923 に答える