<?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>Routes Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/routes/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/routes/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Sat, 06 Mar 2021 09:54:50 +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>Laravel 5.8 CRUD Tutorial with examples</title>
		<link>https://www.scmgalaxy.com/tutorials/laravel-5-8-crud-tutorial-with-examples/</link>
					<comments>https://www.scmgalaxy.com/tutorials/laravel-5-8-crud-tutorial-with-examples/#respond</comments>
		
		<dc:creator><![CDATA[Joydeep M]]></dc:creator>
		<pubDate>Fri, 05 Mar 2021 11:49:05 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[laravel]]></category>
		<category><![CDATA[Laravel beginners]]></category>
		<category><![CDATA[Routes]]></category>
		<category><![CDATA[Views]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">http://www.scmgalaxy.com/tutorials/?p=5418</guid>

					<description><![CDATA[<p>Create Route for View: To write it in a simpler way: Example:- Route::view(‘about’,’aboutme’) -We should create view in structured way(inside [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/laravel-5-8-crud-tutorial-with-examples/">Laravel 5.8 CRUD Tutorial with examples</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"><strong>Create Route for View</strong>:</p>



<pre class="wp-block-code"><code>Syntax: Route::get('uri', function(){return view('view_name')});</code></pre>



<p class="wp-block-paragraph"><strong>To write it in a simpler way:</strong></p>



<pre class="wp-block-code"><code>Syntax:- Route::view method</code></pre>



<p class="wp-block-paragraph">Example:- Route::view(‘about’,’aboutme’)</p>



<p class="wp-block-paragraph"><strong>-We should create view in structured way(inside folder) that means all the views should not be in the view folder and we can make it in structured way by making folder</strong> <strong>in views.</strong></p>



<p class="wp-block-paragraph"><strong>-To create route for view which is inside folder:</strong></p>



<pre class="wp-block-code"><code>Syntax:- Route::get(‘uri’, Function(){
return view(‘folder_name.view_name’)});</code></pre>



<p class="wp-block-paragraph">Example:- Route::get(‘aboutprofile’, Function(){return view(‘admin.profile’)});</p>



<p class="wp-block-paragraph"><strong>-Passing data from Route to view:</strong></p>



<p class="wp-block-paragraph"><strong>*</strong>Data should be in array and in key value/pair.</p>



<p class="wp-block-paragraph">*Inside the view, we can then access each value using its corresponding key.</p>



<p class="wp-block-paragraph">Example 1:-</p>



<pre class="wp-block-code"><code>Route::get(‘contact’, function(){
Return view(‘contactme’,&#91;‘name’=&gt;’Sonam’]);
});
</code></pre>



<p class="wp-block-paragraph">&nbsp;*We can also use the <em>with</em> method to add individual pieces of date to the view.</p>



<p class="wp-block-paragraph">Example:-</p>



<pre class="wp-block-code"><code>Route::get(‘contact’, function(){
return view(‘contactme’)-&gt;with(‘name’,’Sonam’)
});
</code></pre>



<p class="wp-block-paragraph"><strong>-Accessing the data which is passed from Route to view:</strong></p>



<pre class="wp-block-code"><code>&lt;h1&gt;Hello{{$name}}&lt;/h1&gt;</code></pre>



<p class="wp-block-paragraph"><strong>-Returning view from web.php using parameter:</strong></p>



<pre class="wp-block-code"><code>Route::get(‘user/(u_id}’, function($id){
Return view(‘myuser’,&#91;‘id’=&gt;$id]);
});
</code></pre>



<p class="wp-block-paragraph">(<strong>In the User View)</strong></p>



<pre class="wp-block-code"><code>&lt;body&gt;
&lt;h1&gt;User page &lt;/h1&gt;
&lt;h1&gt;{{$id123}}&lt;/h1&gt;
&lt;/body&gt;
</code></pre>



<p class="wp-block-paragraph"><strong>-For multiple parameter:</strong></p>



<p class="wp-block-paragraph"><strong>(In web.php)</strong></p>



<pre class="wp-block-code"><code>Route::get(‘post/{post_id}/comment/{comment_id}’, function($post_id, $comment_id){
Return view(‘mypost’,&#91;‘postid’=&gt;$post_id, ‘commentid=&gt;’$comment_id’]);
});
</code></pre>



<p class="wp-block-paragraph"><strong>(In the Post View)</strong></p>



<pre class="wp-block-code"><code>&lt;body&gt;
&lt;h1&gt;User page &lt;/h1&gt;
&lt;h1&gt;Post Id:{{$postid}}&lt;/h1&gt;
&lt;h1&gt;Comment Id:{{$commentid}}&lt;/h1&gt;
&lt;/body&gt;
</code></pre>



<p class="wp-block-paragraph"><strong>-For making optional parameter:</strong></p>



<p class="wp-block-paragraph"><strong>(In web.php)</strong></p>



<pre class="wp-block-code"><code>Route::get(‘user/(name?}’, function($name=null){
Return view(‘myuser’,&#91;‘name’=&gt;$name]);
</code></pre>



<p class="wp-block-paragraph"><strong>(In User view)</strong></p>



<pre class="wp-block-code"><code>&lt;body&gt;
&lt;h1&gt;User page &lt;/h1&gt;
&lt;/body&gt;
</code></pre>



<p class="wp-block-paragraph">For calling this in the server we can type 127.0.0.1.8000 or 127.0.0.1.8000/name and it will display the content in both scenario without giving error. Though it will not return any name if we do not enter /name.</p>



<p class="wp-block-paragraph"><strong>-For regular expression</strong></p>



<p class="wp-block-paragraph"><strong>(In web.php)</strong></p>



<pre class="wp-block-code"><code>Route::get(‘product/{p_name}’, function($name){
Return view(‘myproduct’,&#91;name’=&gt;$name]);
})-&gt;where(‘p_name’=&gt;‘&#91;A-za-z]+’);
</code></pre>



<p class="wp-block-paragraph"><strong>(In myproduct view file)</strong></p>



<pre class="wp-block-code"><code>&lt;body&gt;
&lt;h1&gt;Product page &lt;/h1&gt;
&lt;h1&gt;{{$name}}&lt;/h1&gt;
&lt;/body&gt;
</code></pre>



<p class="wp-block-paragraph"><strong>To redirect from one view to another view:</strong></p>



<p class="wp-block-paragraph"><strong>(In web.php)</strong></p>



<pre class="wp-block-code"><code>Route::view(‘login’, ‘mylogin’);
Route::view(‘register’,’myregister’)
Route::redirect(‘login’, ‘register’);
</code></pre>



<p class="wp-block-paragraph"><strong>(In View file)</strong></p>



<pre class="wp-block-code"><code>&lt;body&gt;
&lt;h1&gt;Login&lt;/h1&gt;
&lt;/body&gt;
</code></pre>



<p class="wp-block-paragraph"><strong>To fallback:</strong></p>



<p class="wp-block-paragraph"><strong>(In web.php)</strong></p>



<pre class="wp-block-code"><code>Route::fallback(function(){
Return view(‘default;);
});
</code></pre>



<p class="wp-block-paragraph"><strong>In Default View:</strong></p>



<pre class="wp-block-code"><code>&lt;body&gt;
&lt;h1&gt;Default&lt;/h1&gt;
&lt;/body&gt;
</code></pre>



<p class="wp-block-paragraph"></p>



<h2 class="has-text-align-center wp-block-heading"><strong>Controllers</strong></h2>



<p class="wp-block-paragraph"><strong>&nbsp;</strong>Controllers can group related request handling logic into a single class. Instead of defining all of your request handling logic as closures in route files, you may wish to organize this behaviour using controller classes.</p>



<p class="wp-block-paragraph">&#8211; Controllers are stored in the app/Http/Controllers</p>



<p class="wp-block-paragraph">-Controller extends the base controller class included with Laravel.</p>



<p class="wp-block-paragraph"><strong>Defining Controller Class</strong></p>



<pre class="wp-block-code"><code>Run command: php artisan make:controller controller_name</code></pre>



<p class="wp-block-paragraph">Example: php artisan make:controller AboutController</p>



<p class="wp-block-paragraph"><strong>Creating Route for Controller Class</strong></p>



<p class="wp-block-paragraph"><strong>(In AboutController.php)</strong></p>



<pre class="wp-block-code"><code>&lt;?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
	Function show(){
		Return ‘Hello Controller’;}
}
</code></pre>



<p class="wp-block-paragraph"><strong>(In Web.php)</strong></p>



<p class="wp-block-paragraph">Use App\Http\Controllers\AboutControllers;</p>



<pre class="wp-block-code"><code>Route::get(‘about’,&#91;AboutController::class,’show’]);</code></pre>



<p class="wp-block-paragraph"><strong>Syntax:</strong></p>



<pre class="wp-block-code"><code>Route::get(‘URI’,&#91;ControllerName::class,’method_name’]);</code></pre>



<p class="wp-block-paragraph"><strong>Getting parameter in Controller</strong></p>



<p class="wp-block-paragraph"><strong>In AboutController.php</strong></p>



<pre class="wp-block-code"><code>&lt;?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
	Function show(){
		Return ‘Hello Controller’,$name;}
}
</code></pre>



<p class="wp-block-paragraph"><strong>In web.php</strong></p>



<p class="wp-block-paragraph">Use App\Http\Controllers\AboutController;</p>



<pre class="wp-block-code"><code>Route::get(‘about/{name}’),&#91;AboutController::class,’show’]);</code></pre>



<p class="wp-block-paragraph"><strong>To import controller in web.php</strong></p>



<p class="wp-block-paragraph">Use App\Http\Controllers\AboutController;</p>



<p class="wp-block-paragraph"><strong>Controller returning string with parameter</strong></p>



<p class="wp-block-paragraph"><strong>In AboutController</strong></p>



<pre class="wp-block-code"><code>function show($name){
return “Hello Controller”.$name;
</code></pre>



<p class="wp-block-paragraph"><strong>In web.php</strong></p>



<pre class="wp-block-code"><code>Route::get(‘about/{name}’,&#91;Aboutcontroller::class,’show’]};</code></pre>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="576" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/03/1-1-1024x576.jpg" alt="" class="wp-image-5421" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/03/1-1-1024x576.jpg 1024w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/03/1-1-300x169.jpg 300w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/03/1-1-768x432.jpg 768w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/03/1-1.jpg 1366w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph"><strong>Returning View from Controller Class</strong></p>



<p class="wp-block-paragraph"><strong>In AboutControllers</strong></p>



<pre class="wp-block-code"><code>&lt;?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
	function show(){
		return view(‘Hello Controller’);}
}
</code></pre>



<p class="wp-block-paragraph"><strong>In web.php</strong></p>



<p class="wp-block-paragraph">Use App\Http\Controllers\AboutController;</p>



<pre class="wp-block-code"><code>Route::get(‘about’,&#91;AboutController::class,’show’]);</code></pre>



<p class="wp-block-paragraph"><strong>In Views:</strong></p>



<pre class="wp-block-code"><code>&lt;body&gt;
&lt;h1&gt;About my controller&lt;/h1&gt;
&lt;/body&gt;
</code></pre>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="576" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/03/2-1024x576.jpg" alt="" class="wp-image-5420" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/03/2-1024x576.jpg 1024w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/03/2-300x169.jpg 300w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/03/2-768x432.jpg 768w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/03/2.jpg 1366w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/laravel-5-8-crud-tutorial-with-examples/">Laravel 5.8 CRUD Tutorial with examples</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/laravel-5-8-crud-tutorial-with-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
