Laravel 8 multi auth. Redirect users and admins to different pages. Using Laratrust authentication.

Поделиться
HTML-код
  • Опубликовано: 13 июл 2024
  • Github repo: github.com/Norbertho/Laravel-...
    In this video I show how to create laravel 8 multi auth for users like Admin, User, Student, Teacher.... For this laravel 8 authentication I use Laratrust package. We show different page for admin and user, and show different menu for admin and for user. This multi auth system works with laravel 8 fortify, Laravel jetstream, and with LAravel Breeze. After the laravel admin and user login we redirect them to different pages. We using laravel roles and permissions as well.
    My twitter: / norberthalase
    00:00 Intro
    02:42 Setup Laravel Breeze
    05:38 Setup Laratrust package
    12:22 How to assign rols to users like admin
    20:09 How to create a controlller in laravel 8
    34:30 How to protect routes for admin and for different type of users
    #Laravel8MuliAuth #Laratrust #LaravelAuthentication
  • НаукаНаука

Комментарии • 160

  • @farshadvahidifard1515
    @farshadvahidifard1515 3 года назад +9

    HI, at the beginning of the tutorial, you say "it's work with jetstream..." I tried to run it with jetstream but there is no AUTH file in APP/HTTP/CONTROLLERS, could you please help me! Thank You

    • @farshadvahidifard1515
      @farshadvahidifard1515 3 года назад +3

      @@CodeFisher Thank you, but the small thing you forget App/Actions/Fortify/CreateNewUser.php. ;-)

    • @kevinwakhisi7001
      @kevinwakhisi7001 3 года назад

      @@CodeFisher can this concept apply to laravel vue js (I'm still new to laravel )

    • @syazanarejab9675
      @syazanarejab9675 3 года назад

      @@CodeFisher thanks a lot.

    • @subodhpoudel6116
      @subodhpoudel6116 3 года назад +2

      while using jetstream, how can I attach the roles? It does not let me use the `Request $request` variable in the CreateNewUser.php file

    • @Ahmedmansour-xi6er
      @Ahmedmansour-xi6er 3 года назад +1

      @@subodhpoudel6116 just paste this
      user= User::create([
      'name' => $input['name'],
      'email' => $input['email'],
      'password' => Hash::make($input['password']),
      ]);
      $user->attachRole($input['role_id']);

  • @Joan_MV
    @Joan_MV 3 года назад +1

    Wow, thanks so much!! This is just that I needed, I spended a lot of time looking for how to implement that feature in my new site.

  • @hugojeharr2217
    @hugojeharr2217 3 года назад +2

    Your explaination is good because you assume the viewer is a beginner, worth to watch and like.

  • @BucurIonNiculae
    @BucurIonNiculae 2 года назад +2

    A very good tutorial. I finally understood how multiuser works in Laravel. I'm a beginner.

  • @abdullahalnoman9204
    @abdullahalnoman9204 2 года назад +1

    That is awesome. Very clear tutorial on multiAuth

  • @abdullahihussein2393
    @abdullahihussein2393 3 года назад +1

    Well explained. Thank you for this tutorial!!!

  • @kasnitv1851
    @kasnitv1851 3 года назад

    Amazing tutorial, very explicit. thanks a lot for this video

  • @aziz-dailycommentsandmore9086
    @aziz-dailycommentsandmore9086 3 года назад

    Hello and thanks for the video, it really helped me complete my project!! also I study in hungary and I immediately recognized that hungarian english accent lol, thanks again.

  • @CareerSearch
    @CareerSearch 2 года назад +1

    This video feels me professional. Thank you

  • @alirazatawary
    @alirazatawary Год назад +1

    sir thank you so much its very amazing and helpful i followed you step by step and impress my manger

  • @millyhuckle6388
    @millyhuckle6388 2 года назад

    Such a good tutorial!! Thank you :)

  • @kavinprathaban5132
    @kavinprathaban5132 3 года назад +1

    Adequate and sufficient explanation. ❤️

  • @zozozaza8957
    @zozozaza8957 3 года назад

    Merci, ça marche. Après avoir longtemps cherché, je suis tombé dessus et ça m'a vraiment aidé. Thank you !!!

    • @kouvibanaaidahie8556
      @kouvibanaaidahie8556 2 года назад

      Bonjour comment vous allez?
      J'ai suivi exactement ce qu'il a fait mais j'ai un problème avec la methode 'hasRole'. On me dit que ce n'est pas défini

    • @kouvibanaaidahie8556
      @kouvibanaaidahie8556 2 года назад

      Svp aidé moi

  • @digitalcreation327
    @digitalcreation327 2 года назад +1

    Thank you !! It's help me a lot...

  • @nicevtn
    @nicevtn 2 года назад +1

    great tutorial!

  • @seyzeffects
    @seyzeffects 2 года назад

    Thanks for sharing this package

  • @fahrisusaini7156
    @fahrisusaini7156 2 года назад

    Thanks for your video

  • @dlopez079079
    @dlopez079079 3 года назад

    Pretty good video on this topic. I successfully completed it with no problems.

    • @kouvibanaaidahie8556
      @kouvibanaaidahie8556 2 года назад

      How? I am having problems with the hasRole method and I cannot define the route it gives me an error

  • @user-gy2ek3le5s
    @user-gy2ek3le5s 9 месяцев назад +1

    Amazing tutorial, was very helpful to me.

  • @bgdev2683
    @bgdev2683 3 года назад

    Thank you very much, it worked perfectly, I subscribe for more 😁

  • @sammy7238
    @sammy7238 3 года назад

    Good job, thank you very much

  • @ranaarslan4750
    @ranaarslan4750 2 года назад +1

    Excellent

  • @karthick2838
    @karthick2838 3 года назад

    Thank You So Much🤗

  • @jesuschrist6811
    @jesuschrist6811 3 года назад +1

    Very good and usful tutorial. i am proud my child

  • @houarirechache9147
    @houarirechache9147 2 года назад

    thanks a lot sir

  • @jackodhiambo5710
    @jackodhiambo5710 2 года назад +1

    amazing content.

  • @abdelhalim731
    @abdelhalim731 2 года назад +1

    greate job

  • @cletuskingdom
    @cletuskingdom 2 года назад +1

    Thank you for this, although I have been coding this manually; I'll try this out.

    • @eyamagdouli7880
      @eyamagdouli7880 2 года назад

      please can you share how you code this manually!

  • @zuraidiismail1113
    @zuraidiismail1113 3 года назад

    great tutorial

  • @user-vb2pn5we2o
    @user-vb2pn5we2o 2 года назад +1

    very very very very very very very very very very very very very very very THANK YOU

  • @abuwafiy7123
    @abuwafiy7123 3 года назад +2

    thank you for tutorials, next time make tutorial CRUD with multi auth laravel 8

  • @d.l.n.sachinda8508
    @d.l.n.sachinda8508 3 года назад

    valuable video

  • @cowdickerson8102
    @cowdickerson8102 3 года назад

    You explain things well, it's a mess finding someone who doesn't assume you already know everything. By the way can you help me with an issue. I want to store a user id and use it in a condition to show and hide a menu. The menu will be included in four different views. I hope there will be more videos from you, you've earned yourself a subscriber and i'm certain it will be more

  • @1omarfaruq
    @1omarfaruq 3 года назад

    Dear,
    Thanks for your well explain and a good tutorial.
    1 this is more important for a Laravel projects which is moduleing system in Laravel 8, could you please, make a video for how to make a module structure in Laravel 8.
    Thank you for this tutorial!!

  • @ahmedragab7934
    @ahmedragab7934 2 года назад +1

    You missed something in the protection, when the user choose his role he can just open the console and edit the value of any option in the select element and may be he will send an admin value and the admin route will be accessible for him.

  • @Zinaxy14
    @Zinaxy14 2 года назад

    helpfull

  • @yerco75
    @yerco75 3 года назад

    This also works with laravel ui guys if you want the same but using bootstrap instead, that was awesome for my project (sorry for my english if i said something wrong)

  • @jenishshrestha2433
    @jenishshrestha2433 2 года назад +1

    senk you so mats ,besto frendo

  • @proyectoresidenciasdai2288
    @proyectoresidenciasdai2288 3 года назад +1

    Thank you sir! I am pretty new in laravel but I have to create a system with this technology.
    I have a question. In my DB I have to create teacher and students, they are different aspects and I have to create more tables which connect the relations between teachers and students. How can I manage these aspects using laratrust?

  • @twsllc2671
    @twsllc2671 3 года назад

    Nice video help me get pass my user control problem

  • @houndofjustice5
    @houndofjustice5 3 года назад

    Is there gonna be laravel 8 sanctum backend with vue js frontend tutorial video anytime soon?

  • @felixmutai1467
    @felixmutai1467 3 года назад

    Good work I was able to grab the concept I needed, but too many adverts, can't follow for even a minute.

  • @Defaulttt
    @Defaulttt 3 года назад

    Can I update the roles_structure after I added it to the database? Like if there's already there. Can I add more?
    Also, what are those under superadministrator, administrator and user? The users,profile,payments. Can you explain? TIA.

  • @markusaurelius1190
    @markusaurelius1190 2 года назад

    Hi Can I ask you a question? I followed your instructions in both this video and the new one about Laravel Jetstream. I have set up vanilla Laravel Jetstream with TEAMS and also with EMAIL VERIFICATION. It is working. If I want to incorporate LaraTrust can I do this on top of vanilla Laravel Jetstream? I.e. I thought that TEAMS would supply a roles and permissions environment but I do not see the tables in my database. I tried spatie but I find your LaraTrust is much simpler. I do not want to break the vanilla Laravel Jetstream I have set up per above. But I do want to set up the ability to allow access to certain pages if admin and deny if user as you explained in this video.

  • @salvadorfajardo4639
    @salvadorfajardo4639 3 года назад

    So, you put logic in your view (if role is user do this, if role is blog do that)? but the model is MVC. Are you sure is the correct way following MVC ? And thanks for the video !

  • @rajamuruganthirumaran1909
    @rajamuruganthirumaran1909 3 года назад +1

    Hello, Mr @Code Fisher, I create a new user in the " jetstream " project they will not add any enters in the "role_user" table.

  • @Francesco-gi8kg
    @Francesco-gi8kg 3 года назад +2

    Is it possible to use Laratrust with bootstrap auth system?

  • @nicolastorgato9387
    @nicolastorgato9387 3 года назад

    Hi, what if my USER has more or different information than the ADMIN? In your case there is only table, both for user and admin.
    Is there a way to have a table for the simple users and another one for the admins?

  • @ajay2347
    @ajay2347 2 года назад

    thanks this tutorial helps me a lot.., please can you make a tutorial on google authentication from scratch

  • @amarchand1504
    @amarchand1504 2 года назад

    superb so great sir... i love this video. basically if we want to assign more permission how to handle these type of permissions for spacific user. kindly could you help me?

  • @eatwithfatinfarhana8225
    @eatwithfatinfarhana8225 2 года назад

    at 20:01, where did u get the code for //auth route for both in web.php?

  • @natalie-obrien
    @natalie-obrien 2 года назад +1

    Hi , great video but is it possible you can do a version with laravel 8 with jetstream+ livewire ?

  • @harrisonoluchukwuebuka3646
    @harrisonoluchukwuebuka3646 3 года назад

    this is better

  • @darek1272
    @darek1272 3 года назад +2

    I using Laravel 8.35.1 and I did everything like in the movie
    but my "hasRole" is undefined and I try to fix this but I can't find solution. Can You help me?

  • @chandimapri3528
    @chandimapri3528 3 года назад

    Very good explanation. Good teaching. I have one question. Can i install Admin LTE for this project ?
    Thank you.

    • @kouvibanaaidahie8556
      @kouvibanaaidahie8556 2 года назад

      hello have you been able to integrate adminlte and laratrust authentication into laravel 8? If so, how? help me please

  • @tik-tokreccaped7876
    @tik-tokreccaped7876 3 года назад

    hi there after creating the different views and running the project i get a blank page
    for all users

  • @alirazatawary
    @alirazatawary Год назад +1

    please upload next video to manage permissions from admin panel kindly

    • @CodeFisher
      @CodeFisher  9 месяцев назад

      I will upload an updated version soon.

  • @edmarsee
    @edmarsee 2 года назад

    What if you also want to put the My profile on the blog page?

  • @devaes
    @devaes 3 года назад

    thank you . btw is it okay / applicable with basic auth ui ?

    • @yerco75
      @yerco75 3 года назад

      Yes u just nedd a minor changes on the register controller

  • @mihajatianapatriciaraveloa3491
    @mihajatianapatriciaraveloa3491 2 года назад +2

    THANKS SO MUCH FOR THIS TUTORIAL? AND WHAT DO WE DO IF WE WANT THE ADMIN TO APPROVE USERS?

    • @nm-mr3qv
      @nm-mr3qv 2 года назад

      Maybe my answer late , i think you can use status when user registered. Then admin will be approve/change status to approved

  • @umerfarooqchattha5685
    @umerfarooqchattha5685 3 года назад

    Please make a video of laravel8 and vue js components and redirect from one to other... Without run php artisan serve commamd..

  • @CareerSearch
    @CareerSearch 2 года назад +2

    Any crud solution in your tutorial?

  • @essouiseif7010
    @essouiseif7010 3 года назад

    hello thank u for the video

  • @ninanaushad7471
    @ninanaushad7471 2 года назад

    I do not have the RegisteredUserController at 13:19 ? I am using laravel vue

  • @thamodhmadushan5823
    @thamodhmadushan5823 3 года назад

    hi brother,
    i want to update Role.
    ex-:(user update blogwriter)
    how do this?

  • @hanahana2513
    @hanahana2513 2 года назад +1

    I have prblm in method hasRole, it is always undefinded !!

  • @oussamaagoujil7981
    @oussamaagoujil7981 3 года назад

    hello sir , hope you're doing fine .
    i'm having this problem when i change the attachRole method to $request->role_id , when i try to add a user it gives me 404 not found. I can't find the problem.

  • @numansiddique4326
    @numansiddique4326 2 года назад

    how can you send user back on login page with exception (You don't have permission) if he didn't access of web?

  • @technotechlovepreet1852
    @technotechlovepreet1852 3 года назад

    hy sir i want to redirect different url for admin and user..in login time like for admin =admin/dashboard and user for user/dashboard

  • @niveshnamurugan6557
    @niveshnamurugan6557 2 года назад +1

    HasRole is undefined in vscode , pls help me

  • @UdithaMe
    @UdithaMe 3 года назад

    how to allow registration only to Admin after login as admin?

  • @mohammadalaminsiam711
    @mohammadalaminsiam711 2 года назад

    How to register without dropdown and using custom routes for admin and user ? could you please help me

  • @0x0456
    @0x0456 Год назад

    @9:35: How does the users, payments and profile come handy? Does anyone have an example? How do I just show one user role?

  • @JAOcero
    @JAOcero 3 года назад

    how to fix sir I can still access the login route even though I'm already login

  • @emenikemanutd2009
    @emenikemanutd2009 3 года назад

    please how do i move my dashboard.blade.php to a different folder?

  • @webtuxsoluciones8769
    @webtuxsoluciones8769 3 года назад

    Hello, I follow all the steps, but laratrust does not install the seeder that you use.

  • @etitahmina9488
    @etitahmina9488 2 года назад

    how to add voyager admin panel in this authentication with laratrust? I have created multi auth now how can i add admin panel? please help

  • @fatimabartels7447
    @fatimabartels7447 3 года назад

    How I will do it if I don't use a php database just sqlite? where I store the data? I mena in factory? I am new with this laravel thing

  • @z-root8955
    @z-root8955 2 года назад +1

    how can i make that with jetstream

  • @Appelketaart
    @Appelketaart 2 года назад

    I lost the record from role_user table every times i have closed the program and run again. How is to fix it?

  • @marcinmaj3609
    @marcinmaj3609 3 года назад

    Can i use impersonate user. Login to other user without logout?

  • @odoo-learn
    @odoo-learn 2 года назад +1

    I have error in method hasRole() undefind how i can sole that ?

    • @aziznigmatov887
      @aziznigmatov887 2 года назад

      Add
      $user = User::find(Auth::user()->id );
      Then write
      if ($user->hasRole('user')) {
      return view('userdash');
      }

  • @houarirechache9147
    @houarirechache9147 2 года назад

    hi, please i need to know how i can give "Register" only for admin

  • @badissjabou252
    @badissjabou252 3 года назад +3

    HELLO!
    in the dashbordController you use "hasRole"
    i do the same but i have a problem ??
    Undefined method 'hasRole'.intelephense(1013)

    • @martisuper7963
      @martisuper7963 3 года назад +1

      1. In the User.php under "use Illuminate\Notifications\Notifiable;" add "use Laratrust\Traits\LaratrustUserTrait;"
      2. Add "use LaratrustUserTrait;" at the beggining of "class User extends Authenticatable"
      That should be it, if it doesn't work run "composer dump-autoload" and if then still doesn't work then check your database, if you have been changing something directly in "role_user" table (like i did) then you will lose all day for nothing :D

    • @kouvibanaaidahie8556
      @kouvibanaaidahie8556 2 года назад

      @@martisuper7963 And so we shouldn't register a user before using the hasRole method?

    • @manelarousse3889
      @manelarousse3889 2 года назад

      @@martisuper7963 i follow your instructions but it doesn't work

    • @yazanrababa
      @yazanrababa 2 года назад

      @@martisuper7963 oh come on, you are great, thank you

  • @jinshajp9838
    @jinshajp9838 3 года назад

    $user->attachRole($request->role_id);
    already done this
    then how to switch into the admin dashboard and how to register as a admin
    please explain am a beginner....

  • @binibininglavina5167
    @binibininglavina5167 2 года назад

    hi, I just want to ask why Illuminate\Support\ facades\Auth isn't working?

    • @binibininglavina5167
      @binibininglavina5167 2 года назад

      The dashboard didn't showed up even though I type the exact codes you did. Hope you san help me!

  • @emenikemanutd2009
    @emenikemanutd2009 3 года назад

    please how can i use it on jetstream?

  • @imranlashari6578
    @imranlashari6578 3 года назад

    Can anyone guide me that in Laravel 8 after login where credentials passes to check whether the user is authorized or not?
    i want to check weather it is Admin or User to redirect to their respective page.

    • @Nulimitz
      @Nulimitz 3 года назад

      I think its would be best to use middleware if its for routes. then it would be east to separate routes for admin, user, guest

  • @habibaakter7388
    @habibaakter7388 2 года назад

    if i want 4 blogwritter with different email and show different information for each in the same blogwritterdash??? please make a tutoral about this....

  • @jacquesseitshiro5579
    @jacquesseitshiro5579 3 года назад

    how to write to and read from database please

  • @anugrah9346
    @anugrah9346 2 года назад

    how to use laratrust without tailwind...??

  • @sonihidayatulloh9242
    @sonihidayatulloh9242 Год назад

    how i crud user and copywriter in admin sir ?

  • @jenishshrestha8613
    @jenishshrestha8613 2 года назад

    how do i create a user from admin panel

  • @queenofrandomness9391
    @queenofrandomness9391 2 года назад

    i did same steps but i cant find auth in my controllers :(

  • @Niborsixoir
    @Niborsixoir 3 года назад +1

    No estoy en contra de los indios pero aleluya, por fin alguien que habla normal el ingles y que mejor que un nativo angloparlante... puff creo que el acento indio es un tanto desesperante, en serio

  • @muhammadamin8555
    @muhammadamin8555 2 года назад

    Hi, i got an undefined error when using hasRole method…need help

    • @aziznigmatov887
      @aziznigmatov887 2 года назад

      Add
      $user = User::find(Auth::user()->id );

      Then write
      if ($user->hasRole('user')) {
      return view('userdash');
      }

  • @ugyentshomo2066
    @ugyentshomo2066 3 года назад

    sir can you please tell us how to set forget password in laravel 8

  • @widaratan2851
    @widaratan2851 3 года назад

    Thanks for this tutorial. How to integrate Laratrust authentication and AdminLTE dashboard templates in laravel 8, If you don't mind, can @Code Fisher be okay with making a tutorial like that? Thank you for helping.

    • @kouvibanaaidahie8556
      @kouvibanaaidahie8556 2 года назад

      hello have you been able to integrate adminlte and laratrust authentication into laravel 8? If so, how? help me please

  • @jintuthomas6766
    @jintuthomas6766 3 года назад

    hi i have an error Call to undefined method App\Models\User::attachRole()...can u help me?

  • @adityagorefitness
    @adityagorefitness 3 года назад +2

    hey man! thanks for the tutorial. in dashboardcontroller, i am getting an error saying hasRole() is not defined, any ideas on how to fix it?

    • @badissjabou252
      @badissjabou252 3 года назад +1

      i have the same error

    • @ciceroalysson2486
      @ciceroalysson2486 3 года назад

      Me too

    • @martisuper7963
      @martisuper7963 3 года назад +2

      1. In the User.php under "use Illuminate\Notifications\Notifiable;" add "use Laratrust\Traits\LaratrustUserTrait;"
      2. Add "use LaratrustUserTrait;" at the beggining of "class User extends Authenticatable"
      That should be it, if it doesn't work run "composer dump-autoload" and if then still doesn't work then check your database, if you have been changing something directly in "role_user" table (like i did) then you will lose all day for nothing :D

    • @maulanarisky3886
      @maulanarisky3886 3 года назад +1

      me too

    • @gerardonavarro449
      @gerardonavarro449 2 года назад

      @@martisuper7963 would you mind sharing what did you do then?