Загрузка...

#62 Make E-com website in Laravel 5.6 | User Register Form | Add User in table | Logout

In Part 62, we will once again work on user register form and this time we are going to add the user in users table. And will redirect the user to cart page with Account and Logout links at header.

So few of the changes we will make in our Routes and functions so that we can separate login register blade file with register form and login form.

1) Update web.php file :-

i) Update login-register route with GET method only in place of GET/POST method.

// Users Login/Register Page
Route::get('/login-register','UsersController@userLoginRegister');

ii) Create user-register route with POST method only where user will register from register function.

// Users Register Form Submit
Route::post('/user-register','UsersController@register');

2) Update UsersController file :-

i) Create userLoginRegister function in which we will simply return the user to login_register blade file.

ii) Update register function with request data that submitted from the user register form and then added into the users table and redirect to cart page after Auth::Attempt.

While adding user into users table, we need to bcrypt the password to make it secure. Visit below link for more information :-
https://laravel.com/docs/5.6/hashing

Now we will use Auth::attempt to log the user into the website and we will redirect the user to cart page.

3) Update Header Statements :-

Add below header at top of UsersController file :-
use Auth;

4) Update front_header.blade.php file :-

We will now update front header to show Account and Logout links whenever user is logged in otherwise we will show Login link only.

We will use Auth::check() to check whether the user has logged in or not. If Auth::check() is empty, it means the user has not logged in.

5) Create Route (Logout) :-

Now create GET route for users logout in web.php like below :-

Route::get('/user-logout','UsersController@logout');

6) Create logout function :-

Now create logout function in UsersController to logout the user and logout the Auth function as well.

Auth::logout();

We will logout the user with above statement and redirect back the user to index blade file.

So you have seen in video we able to register the user, redirects the user to cart page and then able to logout the user as well.

That's all for now. In next video, we will work on login fucntionality as well. So stay tune...

Thanks for watching :)

Видео #62 Make E-com website in Laravel 5.6 | User Register Form | Add User in table | Logout канала Stack Developers
Яндекс.Метрика

На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.

Об использовании CookiesПринять