app/Http/Controllers/OrdersController.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index()
    {
        if(auth()->user()->isClient()){
            $orders = Order::where('user_id', auth()->user()->id)->orderBy('updated_at', 'desc')->get();
            return view('pages.orders.index') -> with('orders', $orders);
        }
        else if(auth()->user()->isAdmin()){
            $orders = Order::orderBy('updated_at', 'desc')->get();
            foreach($orders as $order){
                if($order->getClient() === null) abort(404);
                $order->client = $order->getClient();
            }
            return view('pages.orders.index') -> with('orders', $orders);
        }
        else abort(404);
    }
public function index ( ) { if ( auth ( ) -> user ( ) -> isClient ( ) ) { $ orders = Order :: where ( 'user_id' , auth ( ) -> user ( ) -> id ) -> orderBy ( 'updated_at' , 'desc' ) -> get ( ) ; return view ( 'pages.orders.index' ) -> with ( 'orders' , $ orders ) ; } else if ( auth ( ) -> user ( ) -> isAdmin ( ) ) { $ orders = Order :: orderBy ( 'updated_at' , 'desc' ) -> get ( ) ; foreach ( $ orders as $ order ) { if ( $ order -> getClient ( ) === null ) abort ( 404 ) ; $ order -> client = $ order -> getClient ( ) ; } return view ( 'pages.orders.index' ) -> with ( 'orders' , $ orders ) ; } else abort ( 404 ) ; }
Display a listing of the resource.
Display a listing of the resource .
// Attach client to every order