1. 注文のModel
 L 商品のModelにbelongToしている
app/Models/Order.php
    public function product1(){
        return $this->belongsTo('App\Models\Product', 'product_id1', 'id');
    }
2. 商品のModel
  L カテゴリーのModelにbelongToしている
app/Models/Product.php
public function category(){
        return $this->belongsTo('App\Models\Category');
    }
3. この状態で、注文一覧、カテゴリー名の検索をしたい。
belongToの検索はwhereHasなので、whereHasを階層化する。
なお、検索ワードはGetメソッドで取得して、変数としてwhereHasに渡す。
controller
$query = '検索ワード';
        $orders = Order::whereHas('product1', function($q1) use($query){
		    $q1->whereHas('category', function($q2) use($query){
			    $q2->where('company', 'like', '%'.$query.'%');
			});
		})->get();
whereHasのqueryを更にwhereHasとする。
これで行ける。
これをOrWhereHasで更に繋げる。
そして、日付の検索条件(whereBetween, whereDate)も加える。
吐きそう。。🤑🤑🤑
 
					 
