<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>logout Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/logout/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/logout/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Mon, 12 Jul 2021 09:27:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>How to Create Multiple Role Based Authentication in Laravel 5.8</title>
		<link>https://www.scmgalaxy.com/tutorials/how-to-create-multiple-role-based-authentication-in-laravel-5-8/</link>
					<comments>https://www.scmgalaxy.com/tutorials/how-to-create-multiple-role-based-authentication-in-laravel-5-8/#respond</comments>
		
		<dc:creator><![CDATA[Joydeep M]]></dc:creator>
		<pubDate>Fri, 16 Apr 2021 07:22:26 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[laravel]]></category>
		<category><![CDATA[laravel project]]></category>
		<category><![CDATA[Login]]></category>
		<category><![CDATA[logout]]></category>
		<category><![CDATA[multi authentication]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=5893</guid>

					<description><![CDATA[<p>In this tutorial we will see how we can create a basic multiple role based authentication page by using Laravel. [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-to-create-multiple-role-based-authentication-in-laravel-5-8/">How to Create Multiple Role Based Authentication in Laravel 5.8</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In this tutorial we will see how we can create a basic multiple role based authentication page by using Laravel. To understand it we should have more than basic understandings of Laravel.</p>



<ul class="wp-block-list"><li>To start it as we all know we have to create a project (xampp/htdocs directory) in our terminal by running the command given below:</li></ul>



<pre class="wp-block-code"><code><span class="has-inline-color has-vivid-red-color">composer create-project --prefer-dist laravel/laravel multi-auth "5.8.*"</span></code></pre>



<pre class="wp-block-code"><code><span class="has-inline-color has-vivid-red-color">cd multi-auth</span></code></pre>



<ul class="wp-block-list"><li>Once we have created the project we will run the make:auth command to create the default login authentication system of laravel.</li></ul>



<pre class="wp-block-code"><code><span class="has-inline-color has-vivid-red-color">php artisan make:auth</span></code></pre>



<ul class="wp-block-list"><li>Now we need to customize the users_table under migration as per our requirement.</li></ul>



<script src="https://gist.github.com/Joydeep-cotocus/5c679518c74fda9d6c42f325145aa6c5.js"></script>



<ul class="wp-block-list"><li>Now we have to create model and migration for role table where we can see the different roles who can login like &#8216;admin&#8217;, &#8216;user&#8217; etc.</li></ul>



<pre class="wp-block-code"><code><span class="has-inline-color has-vivid-red-color">php artisan make:model Role -m
</span></code></pre>



<ul class="wp-block-list"><li>In the roles table we will customize the Schemas as per the requirement.</li></ul>



<script src="https://gist.github.com/Joydeep-cotocus/840aaae005b136e252fd7aa715433d83.js"></script>



<ul class="wp-block-list"><li>So now we have two model naming Users and Roles and both are dependent on each other hence we need to make a relationship between them.</li><li>To create a relationship we will create functions in both the model for the other one by giving the command given below.</li></ul>



<script src="https://gist.github.com/Joydeep-cotocus/33ec12e64aaff627178188a7db5fe3c2.js"></script>



<script src="https://gist.github.com/Joydeep-cotocus/5aa63d070c5f06e585eff7146eb48fe8.js"></script>



<ul class="wp-block-list"><li>In the next step we need to create seeders for each of the model (User , Role). To create the UsersTableseeder and</li></ul>



<p class="wp-block-paragraph">RolesTableSeeder we will run the command given below.</p>



<pre class="wp-block-code"><code><span class="has-inline-color has-vivid-red-color">php artisan make:seed UsersTableSeeder
php artisan make:seed RolesTableSeeder</span></code></pre>



<ul class="wp-block-list"><li>After the following step we need to add<strong> insert</strong> function in the <strong>UsersTableseeder</strong> and <strong>RolesTableSeeder</strong> and also declare the<strong> use Illuminate\Support\Facades\DB;</strong> in both the seeders in the beginning since we will be using DB class in the seeders.</li></ul>



<script src="https://gist.github.com/Joydeep-cotocus/9b4ae503abedb52bffbd0d0d3f50f1f4.js"></script>



<script src="https://gist.github.com/Joydeep-cotocus/a39049e4507a74a9e1af5086278ea1c9.js"></script>



<ul class="wp-block-list"><li>Once we are done with the steps given above we will create a database and link it with the project in the .env file. In this project I have named the database as <strong>corona </strong>(since it is in trend <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f61b.png" alt="😛" class="wp-smiley" style="height: 1em; max-height: 1em;" />) and added that in my .env file as shown below, with that we will keep the username as <strong>root</strong> and leave the password blank.</li></ul>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="604" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/04/env-1024x604.jpg" alt="" class="wp-image-5894" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/04/env-1024x604.jpg 1024w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/04/env-300x177.jpg 300w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/04/env-768x453.jpg 768w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/04/env.jpg 1201w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list"><li>Once done with the database creation we will migrate our tables into the database with the command given below.</li></ul>



<pre class="wp-block-code"><code><span class="has-inline-color has-vivid-red-color">php artisan migrate</span></code></pre>



<ul class="wp-block-list"><li>In the next step we need to define two created seeders files (UsersTableSeeder and RolesTableSeeder) into the DatabaseSeeder.php as shown below:</li></ul>



<script src="https://gist.github.com/Joydeep-cotocus/04883a7777df6cdd2b184a82e7b0788c.js"></script>



<ul class="wp-block-list"><li>Now we need to import our data stored in the Seeder files into the database which we created using the command:</li></ul>



<pre class="wp-block-code"><code><span class="has-inline-color has-vivid-red-color">php artisan db:seed</span></code></pre>



<ul class="wp-block-list"><li>Until here we have set up the database for storing the details which will be provided by the user and now we need to create the controllers and the middleware to authenticate and redirect the users to there respective pages.</li><li>First of all we need to create controller for User and the Admin.</li><li>To create the controller we need to the follow the command given below:</li></ul>



<pre class="wp-block-code"><code><span class="has-inline-color has-vivid-red-color">php artisan make:controller Admin/AdminController</span>
<span class="has-inline-color has-vivid-red-color">php artisan make:controller User/UserController</span></code></pre>



<ul class="wp-block-list"><li>Now we will be creating middleware for the authentication of the Admin and the User.</li></ul>



<pre class="wp-block-code"><code><span class="has-inline-color has-vivid-red-color">php artisan make:middleware AdminMiddleware
php artisan make:middleware UserMiddleware</span>
</code></pre>



<ul class="wp-block-list"><li>Now we will add Auth trait in the AdminMiddleware and UserMiddleware for authentication of the User and the Admin by writing <strong>use Auth;</strong></li><li>In the next step we will add <strong>handle() </strong>function in the AdminMiddleware and UserMiddleware.</li></ul>



<script src="https://gist.github.com/Joydeep-cotocus/7725e51cf1bdd0dcaf413969a858f312.js"></script>



<script src="https://gist.github.com/Joydeep-cotocus/d6bf8d1a3b0aad0ab11530d0c1eed33f.js"></script>



<ul class="wp-block-list"><li>We will also implement Condition for <strong>Admin </strong>and <strong>User</strong> Login in <strong>RedirectIfAuthenticated </strong>which is in <strong>app/Http/Middleware/RedirectIfAuthenticated.php</strong>.</li></ul>



<script src="https://gist.github.com/Joydeep-cotocus/7b9d1f429963d00a585f382596d8dc70.js"></script>



<ul class="wp-block-list"><li>Now we will be implementing condition in the login controller before that we will remove <strong>‘/home’</strong>&nbsp;from protected&nbsp;<strong>$redirectTo = ‘/home’;</strong> since we don&#8217;t want to redirect the page to <strong>Home</strong> after logging in.</li></ul>



<script src="https://gist.github.com/Joydeep-cotocus/17bb714a11deae02aa4965c7a6784023.js"></script>



<ul class="wp-block-list"><li>Likewise we will implement condition in the <strong>ResetPasswordController </strong>and remove <strong>‘/home’</strong>&nbsp;from protected&nbsp;<strong>$redirectTo = ‘/home’</strong>;</li></ul>



<script src="https://gist.github.com/Joydeep-cotocus/d8c4f8af61d240945a32fa91df71ec5c.js"></script>



<ul class="wp-block-list"><li>Once we are done with the above steps we will use AdminMiddleware and UserMiddleware in Kernal.php which is in <strong>app/Http/Kernel.php</strong>.</li></ul>



<pre class="wp-block-code"><code><span class="has-inline-color has-vivid-red-color">use App\Http\Middleware\AdminMiddleware;
use App\Http\Middleware\UserMiddleware;</span></code></pre>



<ul class="wp-block-list"><li>After that we need to define and for defining we will add the command given below in routeMiddleware.</li></ul>



<pre class="wp-block-code"><code><span class="has-inline-color has-vivid-red-color">'admin' =&gt; AdminMiddleware::class,
'user' =&gt; UserMiddleware::class,</span></code></pre>



<ul class="wp-block-list"><li>Now we are almost done with it and need to write the routes for the Admin and the User. </li></ul>



<script src="https://gist.github.com/Joydeep-cotocus/7061dc124e2421b0da98f6792c05e605.js"></script>



<ul class="wp-block-list"><li>Almost done but we need to make the views as well where we can redirect the admin or user once they login.</li></ul>



<p class="wp-block-paragraph">-Create a blade file for Admin dashboard under <strong>resource/views/admin/dashboard.blade.php</strong>.</p>



<p class="wp-block-paragraph">-Create a blade file for User dashboard under <strong>resource/views/user/dashboard.blade.php.</strong></p>



<ul class="wp-block-list"><li>Under the dashboard blades of User and Admin we can write the basic HTML to check whether it is showing it when redirected.</li></ul>



<script src="https://gist.github.com/Joydeep-cotocus/97649d356909a595ee46abe0c281bc3f.js"></script>



<script src="https://gist.github.com/Joydeep-cotocus/773d46c474372fea7049d21c6051d3a6.js"></script>



<p class="wp-block-paragraph"><strong>It&#8217;s good to go now. You can leave a comment if getting any error while following the steps.</strong></p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-to-create-multiple-role-based-authentication-in-laravel-5-8/">How to Create Multiple Role Based Authentication in Laravel 5.8</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/how-to-create-multiple-role-based-authentication-in-laravel-5-8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
