Reputation: 2400
I have 2 tables items and naws. With
Item::where( 'items.item_type' , '=' , $pagetype)->get();
I retrieve the object perfect, but now i wan t to filter on area in the naws table. How can i achieve that?
Model Item:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Item extends Model
{
protected $table = 'items';
public function naw()
{
return $this->hasOne('App\Naw');
}
}
Upvotes: 1
Views: 160
Reputation: 2400
Awnser:
return Item::with([
'naw' => function($query) use ($slug)
{
$query->whereArea($slug);
}
])->where( 'items.item_type' , '=' , $pagetype)->get();
Upvotes: 1