Issue
I started coding laravel and everything was fine till I wanted to get the result based on the user, how to do it, what do I need to do?.
Solution
You can use where clause.
Suppose you wanna fetch all the blogs of a user.
like:
Blog::where('user_id', Auth::user()->id)->get();
// Auth::user()->id returns the logged in user's id.
Or
create a relation in User model
App\Models\User
use App\Models\Blog;
public function blogs()
{
return $this->hasMany(User::class, 'user_id', 'id');
}
Then
Auth::user()->blogs;
Answered By - Aniket Das
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.