synerops's avatar

Laravel beginner guide

im in practice mode, i have simple project not much complicated, will be having Role: super-admin, admin, manger and user.

---Manger can create only user can view/delete/update (user profile, user post etc) ---Users have limit access only, like create/update/view ---Only admin can create user role like users, admin, manger and can delete posts / any delete options ---Only admin can update /reset password (email reset will not be used)

Should i use laravel start kit like breeze or jetstream or should i use my own custom coding

0 likes
7 replies
Tray2's avatar

I suggest using Breeze for almost all projects.

Jetstream is great but it adds a lot of more complicated things that you as a beginner don't really need yet.

I suggest getting a Subscription here, there are quite a lot of good fun beginners projects to follow along. However I do strongly recommend watching the free 30 Days to learn Laravel 11, it covers your exact question.

https://laracasts.com/series/30-days-to-learn-laravel-11

1 like
synerops's avatar

@Tray2 i have taken that course which make crystal clear but this tutorial doesn't have user role

Tray2's avatar

@synerops Like @jlrdw says, there is a big difference between authentication and authorization. Authentication allows you to log into the system, while authorization allows you to do things inside the system after being authenticated. Those authorities are usually handled by roles, one such roll could be admin.

There are a lot of ways to do that built into Laravel.

https://laravel.com/docs/11.x/authorization

If it is just one admin you could do something very simple like

//User model

public function isAdmin()
{
	return $this->id === 1;
}	

And in your controller,

if (Auth::user()->isAdmin()) {
   return view('products.create');
}

Be aware that this requires the admin user to have the id of one.

There is also a package from Spatie that helps with roles.

https://spatie.be/docs/laravel-permission/v6/introduction

Ben Taylor's avatar

You might want to try building a more dynamic role/permissions system where you can create roles on the fly without hard coding a few.

1 like
synerops's avatar

@Ben Taylor can you suggest me any beginner tutorial for user roles

jlrdw's avatar

@synerops Roles aren't the main thing.

  • A user logs in (and has either one or more roles)
  • Authorization determines what that logged in user with their role /s can or cannot do.

So if we are talking about (just example here) can they edit certain data. They have to have authorization to edit.

There are many videos on this already and a whole chapter covering authorization.

Please or to participate in this conversation.