How to Create Admin User in Laravel: Tinker or Seeds?

How to Create Admin User in Laravel: Tinker or Seeds?

Laravel Daily

3 года назад

16,074 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Serdar Myradov
Serdar Myradov - 08.06.2022 09:44

thank you...

Ответить
Андрей Галушко
Андрей Галушко - 23.02.2022 22:10

Спасибо! всё просто и понятно! для буду использовать seed (мне показалось так удобнее), прекрасного дня из России! 🇷🇺

Ответить
BINGO ONE
BINGO ONE - 30.12.2021 18:20

Thank you very much, bro. It's just take me 2 days until now. I'm a fresher!

Ответить
ivandez
ivandez - 10.03.2021 05:47

thanks buddy

Ответить
Дмитрий Стамбула
Дмитрий Стамбула - 19.02.2021 19:05

Artisan command for creating admin is better, if you want to give different names, email, or pass

Ответить
Andre Allen
Andre Allen - 19.02.2021 06:48

Getting this error at C:\xampp\htdocs\laravel\jetproj\database\seeders\RoleSeeder.php:16
12▕ * @return void
13▕ */
14▕ public function run()
15▕ {
➜ 16▕ Role::create(['name' => 'Administrator']);
17▕ Role::create(['name' => 'Doctor']);
18▕ Role::create(['name' => 'Patient']);
19▕ }
20▕ }
I think something is missing that wasn't demonstrated in the video

Ответить
Andre Allen
Andre Allen - 19.02.2021 05:18

Help, I keep getting an error in RoleSeeder.php line 17 when I run the migrate command.

Ответить
Jan Lawrence Madali
Jan Lawrence Madali - 30.01.2021 08:11

What if I need to logging in using student number, instructor number, and admin number, and their password? Is this the same logic in the register you've created?

Ответить
Kasts Echo
Kasts Echo - 21.01.2021 03:32

You could use a factory instead of calling create directly on the model. Since factories are actual classes in Laravel 8, you could even define a state with how certain fields would be in that state. And then, for example, you could run User::factory(['name' => 'Name', 'email' => '[email protected]'])->admin()->create(); (After importing the user model in the seeder or tinker.)

Ответить
Job Sunday Owonubi
Job Sunday Owonubi - 20.01.2021 18:03

Thanks a lot for this. Please, I have a request/question.
You see, I am new to Laravel and I started with Laravel 8.
I have issues understanding "guards" and the differences between "guards" and "middlewares".
I'd also be grateful if anyone else could help me out here. I just wanna get a hold of it.
@laravelBusiness, I'll be happy if you could help me with links or a video on guards in laravel 8.
Thanks very much.

Ответить
Giedrius Budnikas
Giedrius Budnikas - 20.01.2021 17:49

I don't think it's a good idea to use seeders for this purpose since you'll be leaving admin credentials (including the password) in your VCS.

Ответить
Harsha Subasinghe
Harsha Subasinghe - 20.01.2021 16:19

I'm working on a Laravel + Vue (SPA) project and I'm currently undecided on what to use for authentication. The project already has Spatie installed and configured with couple of user roles and people have recommended me to use Sanctum on top of that for issuing tokens. I'm wondering how would I go about doing that, especially on how to handle Vue routes with Spatie user roles. Do I have to send the logged in user role on each route request back to the server to see if the user has the required permissions with Spatie? Can you please make a small tutorial video on that? It would be much appreciated. Because the documentation on Sanctum alone is not that helping when it comes to dealing with user roles. Thanks in advance.

Ответить
Yamil Coloma
Yamil Coloma - 20.01.2021 15:03

Just what i needed for my project, it's like you read my mind. Thank you very much

Ответить
sivatirumalasai u
sivatirumalasai u - 20.01.2021 12:16

hi sir i have a serious problem in laravel authentication i was been tried in so many ways but i couldn't found the solution my problem is auth::check() and auth::user() are working in same method but when i try to get Auth::user() in another method of same controller getting null please help to sort out the issue
public function logincheck()
{
dd(Auth::user());
//returns null always
}
public function login()
{
$user=User::find(2);
$auth=Auth::attempt(['email' => '[email protected]', 'password' => '123456']);
//dd(Session::flash('user_signup','sai'));
dd(Auth::check());
//here working fine
}

Ответить
Roman Reigns
Roman Reigns - 20.01.2021 11:46

pl make a video on laravel job queue chain and batch
if possible with telescope or horizon for better understading

Ответить
ward
ward - 20.01.2021 10:49

So, essentially, after you do that, you have an admin login page and flow behind it where it checks for credentials and if they have the specific role?

Yesterday was dealing with really similar issue - admin logins in a Sanctum app which should be stateful. Decided to create a custom guard & user provider to check ability and return the user (both admins and users in the same table). Otherwise it seems like I would have to stick a lot of stuff into existing login logic.

Ответить
Phyo Thiha
Phyo Thiha - 20.01.2021 09:43

Tip: If you have multiple database connections in your app, do not forget to add --database flag to specify which connection you want to use when seeding.

Ответить
Nico Deblauwe
Nico Deblauwe - 20.01.2021 09:37

I typically use a command for that task, as it allows for variable input, so no hard coded data. But then, you're very close to the tinker solution, with the need to have local (ssh) access.

Ответить
Edvard Aliev
Edvard Aliev - 20.01.2021 09:13

Rails style creating <3

Ответить
hamza shan
hamza shan - 20.01.2021 09:09

Could u please make video on one to one chat and group chat in laravel pusher and vuejs etc.

Ответить
amer qureshi
amer qureshi - 20.01.2021 09:03

Can you please please make a video on laravel vapor because i only understand your videoes or documentation .

Ответить