P
P
Pavel2015-06-09 09:06:52
Laravel
Pavel, 2015-06-09 09:06:52

How to properly use relationships in Laravel?

Good day, I ask for help from those who know. There is no way to organize the next request within eloquent

SELECT goods.colony, goods.quantity, goods_data.category, goods.goods_id 
FROM goods
INNER JOIN goods_data ON goods.goods_id = goods_data.id
WHERE goods_data.category = 15 AND goods.region = 1

Goods Model
public function category()
  {
    return $this->belongsToMany('App\Models\GoodsData', 'id', 'goods_id');
  }

  public static function getCategoryGoods($id, $region)
  {
    return Goods::where('region', '=', $region)->with('category')->where('category','=', $id)->paginate(18);
  }

Thanks in advance for your help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-06-09
@Volde

laravel.com/docs/5.0/eloquent#querying-relations

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question