I'm making a blog in laravel. You can only create posts if you as user have logged in at least 5 times. I have made a logincounter, which works. Using the following code in my logincontroller:
protected function authenticated(Request $request, $user)
{
$user->logincount ;
$user->save();
}
If I log in 5 times, it shows 5 in the database. Now, i want to create a function that checks if I have logged in 5 times or more before directing me to the /create page. The function I tried to put in the postcontroller doesn't work:
public function create(){
$user = User::all();
if ($user->logincount > 5) {
return view('create');
}
}
The error I get is the following: Property [logincount] does not exist on this collection instance.
This does not work, Laravel doesn't recognize logincount even after I put use App/Model/User. What am I doing wrong?
CodePudding user response:
Did you set your $user variable ?
Like $user = \Auth::user()
for example