Issue
I have a route : Route::get('/TransactionHistory','QuoteController@transactionHistory');
In Controller QuoteController, I have a function as:
public function transactionHistory(){
if(Auth::user()->isAdmin())
{
$res= DB::table('products_products')
->select('users_users.display_name','products_products.name','products_products.id','products_products.user_id','products_products.quantity_type','buy_product.price','buy_product.rating','buy_product.mileage_name','buy_product.id as buy_id')
->join('buy_product','products_products.id','=','buy_product.product_id')
->join('users_users','buy_product.user_id','=','users_users.id')
->get();
}
else{
$u_id=auth()->user()->id;
$res= DB::table('products_products')
->select('products_products.name','products_products.id','products_products.user_id','products_products.quantity_type','buy_product.price','buy_product.rating','buy_product.mileage_name','buy_product.id as buy_id')
->join('buy_product','products_products.id','=','buy_product.product_id')
->where('buy_product.user_id','=',$u_id)
->get();}
return view('templates::pagetwigs/transaction-history')->with('details',$res);
}
On routing the path I got error as :Call to a member function isAdmin() on null
How to fix this.
Solution
Add middleware in the route or in the constructor of controller as shown:
public function __construct()
{
$this->middleware('auth');
}
This will not allow you to access the page unless you are logged in . This will always check that Auth::user()
is not null
Answered By - Manmeet Singh Raina Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.