<?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>route &#8211; The SIGMA</title>
	<atom:link href="https://danushka96.github.io/sigma/index.php/tag/route/feed/" rel="self" type="application/rss+xml" />
	<link>https://danushka96.github.io/sigma/</link>
	<description>&#60;For Those Who Code/&#62;</description>
	<lastBuildDate>
	Sat, 02 Mar 2019 16:57:34 +0000	</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.1.1</generator>
	<item>
		<title>Laravel- Middleware</title>
		<link>https://danushka96.github.io/sigma/index.php/2018/09/14/laravel-middleware/</link>
				<comments>https://danushka96.github.io/sigma/index.php/2018/09/14/laravel-middleware/#comments</comments>
				<pubDate>Fri, 14 Sep 2018 03:10:55 +0000</pubDate>
		<dc:creator><![CDATA[Gayan Sampath]]></dc:creator>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[laravel]]></category>
		<category><![CDATA[middleware]]></category>
		<category><![CDATA[route]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">https://danushka96.github.io/sigma/?p=1251</guid>
				<description><![CDATA[<p><span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">4</span> <span class="rt-label rt-postfix">minutes</span></span> ආයුබෝවන්! කොහොමද යාලුවනේ..ඔන්න මම අදත් ආවා laravel framework එකේ තියන තවත් future එකක් පිලිබදව විස්තරත් සමගින්..මුලින්ම කියන්න ඕනි ඔයාලා කාට හරි අපේ මුල පාඩම් ටික මගහැරුනනම් මෙන්න මෙතනින් ගිහින් බලන්න පුලුවන්..හරි අපි එහෙනං අද පාඩමට බහිමු.අද පාඩම තමයි middleware. ඇත්තටම laravel වල තියන ගොඩක් හොද future එකක් තමයි middleware කියන්නේ..කෙටියෙන්ම<a class="moretag" href="https://danushka96.github.io/sigma/index.php/2018/09/14/laravel-middleware/"> Read more&#8230;</a></p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/09/14/laravel-middleware/">Laravel- Middleware</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></description>
								<content:encoded><![CDATA[<span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">4</span> <span class="rt-label rt-postfix">minutes</span></span><p>ආයුබෝවන්! කොහොමද යාලුවනේ..ඔන්න මම අදත් ආවා laravel framework එකේ තියන තවත් future එකක් පිලිබදව විස්තරත් සමගින්..මුලින්ම කියන්න ඕනි ඔයාලා කාට හරි අපේ මුල පාඩම් ටික මගහැරුනනම් <a href="https://danushka96.github.io/sigma/index.php/category/web-development/laravel/" target="_blank" rel="noopener">මෙන්න මෙතනින්</a> ගිහින් බලන්න පුලුවන්..හරි අපි එහෙනං අද පාඩමට බහිමු.අද පාඩම තමයි middleware. ඇත්තටම laravel වල තියන ගොඩක් හොද future එකක් තමයි middleware කියන්නේ..කෙටියෙන්ම කිව්වොත් middleware එකක් කියන්නේ user හා request එක අතරමැද තියන layer එකක්. මෙන්න මේ layer (middleware ) එකෙන් තමයි user ට system එක access කරන්ට permition ලබා දෙන්නේ ..</p>
<p>laravel folder structure එක ගත්තොත් middleware එක තියෙන්නේ App/Http/Middleware කියන තැන. මේ Middleware folder එක ඇතුලට ගියාම ඔයාලට දැකගන්න පුලුවන් laravel වල default එන middlewares කිහිපයක්ම තියනවා.(VerifyCsrfToken , Authenticate , EncryptCookies. ..etc).අපිට ඕනි නම් middleware එකක් හදන්න පුලුවන්</p>
<pre>php artisan make:middleware &lt;middleware_name&gt;</pre>
<p>කියන artisan command එක run කරලා.middleware එකක් හදා ගත්තට පසුව අපි පලමුවෙන්ම කරන්න ඕනි දේ තමයි හදාගත්ත middleware එක App/Http/Kernel.php එකේ register කර ගන්න එක. හරි ඔන්න ඕකයි සිද්ධිය..☺☺..පොඩ්ඩක් පොඩ්ඩක් අව්ල් වගේනං අපි පොඩි උදාහරණයක්ම ඇරගෙන වැඩේ කරලා බලමුකෝ..😃😃</p>
<p>හරි මම middleware එකක් හදා ගන්නවා checkIp කියලා..</p>
<pre>php artisan make:middleware checkIp</pre>
<p>ඊට පස්සේ ඒ හදා ගත්ත middleware එක මෙන්න මේ විදියට kernel එකේ register කර ගන්නවා..</p>
<pre>&lt;?php namespace App\Http; use Illuminate\Foundation\Http\Kernel as HttpKernel; class Kernel extends HttpKernel { /** * The application's global HTTP middleware stack. * * These middleware are run during every request to your application. * * @var array */ protected $middleware = [ \App\Http\Middleware\CheckForMaintenanceMode::class, \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, \App\Http\Middleware\TrimStrings::class, \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, \App\Http\Middleware\TrustProxies::class, ]; /** * The application's route middleware groups. * * @var array */ protected $middlewareGroups = [ 'web' =&gt; [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' =&gt; [
            'throttle:60,1',
            'bindings',
        ],
    ];

    /**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth' =&gt; \App\Http\Middleware\Authenticate::class,
        'auth.basic' =&gt; \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' =&gt; \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'cache.headers' =&gt; \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' =&gt; \Illuminate\Auth\Middleware\Authorize::class,
        'guest' =&gt; \App\Http\Middleware\RedirectIfAuthenticated::class,
        'signed' =&gt; \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle' =&gt; \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'verified' =&gt; \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
        
        'checkIp'=&gt; \App\Http\Middleware\checkIp::class,
    ];
}


</pre>
<p>හරි මට දැන් කරන්න ඕනි දේ තමයි 127.0.0.1 කියන Ip address එකින් request එකක් ආවොත් එයා system එකට ඇතුලු වෙන එක වලක්වන එක. එතකොට අපි checkIp කියන middleware එකේ මෙහෙම කලානම් හරි නේද&#8230;</p>
<p><img src="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/ch-300x211.jpg" alt="" width="635" height="447" class=" wp-image-1289 aligncenter" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/ch-300x211.jpg 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/ch.jpg 632w" sizes="(max-width: 635px) 100vw, 635px" /></p>
<p>හරි දැන් මෙන්න මේ විදියට rote එකයි view එකකුයි set කරලා run කරලා බලන්නකෝ&#8230;</p>
<p>Route ;</p>
<pre>Route::get('/home',function(){
    return view('testView.home');
})-&gt;middleware('checkIp');

</pre>
<p>output</p>
<p><img src="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/check-300x133.jpg" alt="" width="686" height="304" class=" wp-image-1256 aligncenter" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/check-300x133.jpg 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/check-768x340.jpg 768w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/check-1024x454.jpg 1024w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/check.jpg 1354w" sizes="(max-width: 686px) 100vw, 686px" /></p>
<p>වැඩේ හරි නේද&#8230;127.0.0.1 කියන ip එකෙන් එන requests වලට system එක access කරන්න එක middleware එකෙන් වලක්වලා තියෙන්නේ..</p>
<p>ඔන්න ඔය විදියට route එකට middleware එක set කරනවට අමතරව අපිට පුලුවන් middleware එක controller එකක් ඇතුලට set කරන්න&#8230;එහෙම කලාම වෙන්නේ ඒ controller එකේ තියන සියලුම methods සදහාම middleware එකෙන් ආරක්ෂාවක් සැලසීමයි..controller එකට middleware එක අපි set කරන්නේ __construct() කියන method එක එකේදී..හරි අපි එහෙනං ඒකත් කරලා බලමු.</p>
<p><img src="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/middleware-300x185.jpg" alt="" width="635" height="392" class=" wp-image-1290 aligncenter" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/middleware-300x185.jpg 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/middleware.jpg 632w" sizes="(max-width: 635px) 100vw, 635px" /></p>
<p>දැන් පුරුදු විදියටම route එකයි view එකයි set කරලා output එක බලන්නකෝ&#8230;</p>
<p>Route -&gt;</p>
<pre> Route::get('/home','studentController@index');
</pre>
<p>Output</p>
<p><img src="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/check-300x133.jpg" alt="" width="672" height="298" class="wp-image-1256 aligncenter" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/check-300x133.jpg 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/check-768x340.jpg 768w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/check-1024x454.jpg 1024w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/check.jpg 1354w" sizes="(max-width: 672px) 100vw, 672px" /></p>
<p>ඔන්න ඔය විදියට තමයි middleware එකක් set කරන්නේ..middleware එකට වැඩි ගනනක් අපිට set කරන්න ඕනිනම්, middlewares ටික __constructor() method එකේ parameters විදියට අපිට pass කරන්න පුලුවන්.හරියට මෙන්න මේ විදියට&#8230;</p>
<p>demo1,demo2,demo3 කියලා middlewares තුනක් මං ගන්නම්..</p>
<pre>public function __construct(){
        $this-&gt;middleware('demo1','demo2','demo3');
}
</pre>
<p>ඔන්න ඔය විදියට තමයි multiple middlewares set කරන්නේ&#8230; middlewares ගොඩක් තියනවනම් controllers විශාල ගානකට set කරන්න ආමාරුයි නේ&#8230;😯😯 අන්න ඒ නිසා අපිට පුලුවන් ඒවා kernel එකේදීම ඒවා ටික group කරගන්න..හරි මගේ demo1,demo2 සහ demo3 කියන middlewares ටික group කරලා ඒකට මම නමක් දෙනවා demo කියලා&#8230;</p>
<pre>    protected $middlewareGroups = [
        'web' =&gt; [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' =&gt; [
            'throttle:60,1',
            'bindings',
        ],

        'demo'=&gt;[
            'demo1',
            'demo2',
            'demo3',
        ],
    ];


</pre>
<p>දැන් middleware එක controller එකට set කරමු&#8230;</p>
<pre>public function __construct(){
        $this-&gt;middleware('demo');
}
</pre>
<p>හරි අපි දැන් හිතමු කලින් database එකේ ඉන්න user කෙනෙක්ට system එක access කරන එක වලක්වන්න ඕනි කියලා&#8230;අන්න එතකොට middleware එක set කරන්නේ කොහොමද කියලා දැන් අපි බලමු.<br />
මගේ database එකට නමක් දෙනවා studentdatabase කියලා..ඒකේ තියන student table එක සලකමුකෝ&#8230;</p>
<p><img src="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/database-300x135.jpg" alt="" width="627" height="282" class="wp-image-1257 aligncenter" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/database-300x135.jpg 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/database-768x346.jpg 768w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/database-1024x461.jpg 1024w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/database.jpg 1110w" sizes="(max-width: 627px) 100vw, 627px" /></p>
<p>දැන් මට ඕනි name එක &#8216;smith&#8217; කියලා තියන student , system එක access කරන එක වලක්වන්ට..එතකොට route එක මෙන්න මේ විදියට set කරන්න පුලුවන්..</p>
<pre> Route::get('/profileInfo',function(){
    return view('testView.prof');
})-&gt;middleware('profile:smith');

</pre>
<p>route එක ඔන්න ඔය විදියට set කරන්න පුලුවන්..middleware එක මෙන්න මේ විදියට define කලානම් හරි නේද..</p>
<p><img src="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/prof-300x254.jpg" alt="" width="586" height="496" class=" wp-image-1297 aligncenter" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/prof-300x254.jpg 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/prof.jpg 622w" sizes="(max-width: 586px) 100vw, 586px" /></p>
<p>Output එකත් බලන්නකෝ&#8230;</p>
<p><img src="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/name-300x129.jpg" alt="" width="585" height="252" class=" wp-image-1258 aligncenter" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/name-300x129.jpg 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/name-768x331.jpg 768w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/name-1024x442.jpg 1024w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/name.jpg 1366w" sizes="(max-width: 585px) 100vw, 585px" />;</p>
<p>හරි නේද &#8230;&#8217;smith&#8217; user ට system එක access කරන්න දෙන එක middleware එකෙන් වලක්වලා තියෙන්නේ&#8230;.</p>
<p>හරි ඔන්න ඔය ටික තමයි middleware එක ගැන කියන්ට තියෙන්නේ&#8230;අදට පාඩම ඉවරයි..ඔයාලගේ අදහස් කියලා comment එකක් දාන්නත් අමතක කරන්න එපා..project එකට අදාල source code එක පහල තියන link එකට ගිහින් බලාගන්න පුලුවන්..සුබ දවසක් හැමෝටම !</p>
<p><a href="https://github.com/GayanSampathManamendra/demoProject">GitHub Source Code</a></p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/09/14/laravel-middleware/">Laravel- Middleware</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></content:encoded>
							<wfw:commentRss>https://danushka96.github.io/sigma/index.php/2018/09/14/laravel-middleware/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
							</item>
	</channel>
</rss>
