Is it possible to create a custom query builder inside a model and return the query? Not a stressing issue but would be helpful.
/* Controller */
public function getOrders()
{
$orders = \App\Order::where('is_new', 1)->getFromUserStore();
}
/* Order Model */
public function getFromUserStore()
{
if(\Auth::user()->store->id == 1)
{
return $this->get();
}
else
{
return $this->where('status_id', 1)->get();
}
}
Thanks
useoperator for your namespace to avoid using the backslash all the time. For your controller, your shoulduse App\Order;and for your modeluse Illuminate\Support\Facades\Auth;use.. is there a performance issue with using the backslash? Thanks for the input.