Issue
I want to declare a variable $id
This id will be the Auth::id()
Now what will be the apporach?
Code:
private static $id;
public function __construct()
{
$this->id = Auth::id();
}
But this id is not accessible from function Query.
Invoice::where([
['userID', '=', $id],
['created_at', '=', $todayDate]
])->get();
Giving error in this line: ['userID', '=', $id],
Undefined Variable $id.
Thanks for Advance..
Solution
public function __construct(){
self::$id = Auth::id();
}
NOTE: If there is any static
member function or variable in the class, we cannot refer it using the $this
.
Just use like below
Invoice::where([
['userID'=>self::id],
['created_at'=>$todayDate]
])->get();
Answered By - A.A Noman Answer Checked By - Robin (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.