What is diffrence between Authentication and Middleware at Laravel? - php

Before i was using codeigniteur after the release of version 4CI i decided to learn laravel 7 now i am in learning stages of laravel 7 master version.
i am little confused and explored alot the documentation of laravel but i not found the solution might be my method of exploring or understanding documentation of laravel is not correct.
i have seen videos on YouTube that made me confused as some people use
php artisan make:auth
for creating user authentication but some people use
php artisan make:middleware
for creation user and some other uses unusall
$req->session()->put($user);
Now i understand that last method is just manual method for using user authentication but i not understand the diffrence between auth and middleware
Thank you in advance for your explanation

Middlewares allows you to add you to intercept your requests and add logic to them before they are pipelined to Controllers.
In laravel Authentication by default is done using Auth Midddleware.The logic to detect whether the user is logged in is done over here.
There is no limitation that you can only use middleware with relation to authentication only.

Related

Laravel 8.0 best practice for setting up route for admin and non-admin role

I have these 2 users in my system (admin and non-admin) and I'm reading the Laravel Docs to know the proper and best practice in knowing how to separate the admin to non-admin, and the separation of roles would reflect on the Laravel Blade.
I was familiar with setting up the user authentication using the php artisan make:auth command in the lower version of Laravel. Reading the current docs of Laravel (8.0), it seems like this command is not present in the current documentation anymore. It seems like Laravel would like to promote Laravel Breeze rather than set up your own (or manual) user role authentication.
Now, I do not like to download a package for creating a user role authentication without knowing how to set it up manually.
Is there a simple, effective, and secure way of authenticating the roles of the user of the system manually?

Laravel 5.3 Completely replace default auth by Cartalyst/Sentinel

I have fresh project on Laravel 5.3 and I want to user Cartalyst/Sentinel as default auth and roles manager.
I tried to find some documentation about - how to make Sentinel default Auth manager, but don't find any enough accurate answers.
Could someone provide with step-by-step instruction - what and where need to be changed, replaced, added to use Sentinel in right way?
Documentation of both the sites have instructions for this :
1) Laravel - https://laravel.com/docs/5.3/authentication#adding-custom-guards and https://laravel.com/docs/5.3/authentication#adding-custom-user-providers
2) Sentinel - https://cartalyst.com/manual/sentinel/2.0#laravel-5
Follow what Sentinel guys have to say for now. Understanding how Laravel manages to allow custom Auth system will help you as well.

Do stuff after login/logout in Laravel 5.2

I'm a newbie in Laravel framework
I faced a problem when implementing auth in Laravel 5.2. So i used the make:authof Laravel 5.2 to create a simple login/register/logout mechanism, but i want to do something after login/logout (more specific is i want to send a $request base on username and password (access token)). My problem is Laravel 5.2 make all the authentication encapsulated in Route::auth(); so i don't know where to put my code to, i tried to put the code in AutheticatesUsers.php file, my supervisor said to me i shouldn't put the code in the core file of Laravel because it can change when the framework update. So where i can put the code to.
Any help will be greatly appreciated. Thanks!
In laravel 5.2, you can override auth methods in AuthController.php(allow you custom laravel auth) that is login, logout, register... if you want do something after authenticating just override method authenticated.

Is there a way to use laravel 4.2 authentication without a database?

I am currently developing one plugin of a few larger projects. To make testing easier, I created a separate project and will copy the code to the different projects after the plugin is well-tested.
The plugin will be using the authentication methods of the bigger project, so I don't want to create another one during testing. However, as some functions require testing with authentication, I will need to try using the authentication class with minimal set-up. So, is there a way to use the authentication class to do simple login/logout without a database?
If I understand you correctly, you need your own auth auth provider.
You can read about it in docs
Edit:
Laravel 4.2 doc

How to use Laravel's auth middleware password-reset feature without scaffolding

I removed Laravel's scaffolding with the command php artisan fresh. I read the Auth middleware documentation, but it didn't talk about a specific feature, the password-reset. It only explains its use with the scaffolding, but not if I removed it. There is chapter "Manuel authentication" for common authentication methods, such as "determining if a user is authenticated", but nothing about password-reset.
Other point, does this middleware need specific rows in the DB tables I created with migrations ? Especially "users" and "password_resets" tables configured in the app\config\auth.php file.
This problem may seem simple, but I didn't find any clue in the documentation.
Thanks for help !

Categories