Is there a shorthand way to identify the columns of each table by creating the query like this?
$product = Product::with(['order'])->where('user_id','=',\Auth::user()->id)->find($id);
For example specifying something like this:
->where('order.user_id','=',\Auth::user()->id)
user_id is a field from the order table, the example doesn't work as it doesn't recognize the user_id field .
Or for these type of queries I need to use if or if the buldier DB::
That's what the whereHas function is for, which performs a query on the relation:
More information in the documentation: https://laravel.com/docs/5.4/eloquent-relationships#querying-relationship-existence