<?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>boostrap Archives - Nikhil Patel</title>
	<atom:link href="https://nikhilpatel.in/tag/boostrap/feed/" rel="self" type="application/rss+xml" />
	<link>https://nikhilpatel.in/tag/boostrap/</link>
	<description>Tech Tips, Tutorials &#38; Innovation at Your Fingertips.</description>
	<lastBuildDate>Sat, 25 Sep 2021 11:51:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://nikhilpatel.in/wp-content/uploads/2021/01/cropped-np500X500-1-32x32.png</url>
	<title>boostrap Archives - Nikhil Patel</title>
	<link>https://nikhilpatel.in/tag/boostrap/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Record &#038; upload video from browser using JS &#038; Laravel-8</title>
		<link>https://nikhilpatel.in/record-upload-video-from-browser-using-js-laravel-8/</link>
					<comments>https://nikhilpatel.in/record-upload-video-from-browser-using-js-laravel-8/#comments</comments>
		
		<dc:creator><![CDATA[Nikhil Patel]]></dc:creator>
		<pubDate>Sat, 25 Sep 2021 10:25:00 +0000</pubDate>
				<category><![CDATA[Js]]></category>
		<category><![CDATA[Laravel]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[VideoJs]]></category>
		<category><![CDATA[blade]]></category>
		<category><![CDATA[boostrap]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[laravel]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[videojs]]></category>
		<guid isPermaLink="false">https://nikhilpatel.in/?p=394</guid>

					<description><![CDATA[<p>The post <a href="https://nikhilpatel.in/record-upload-video-from-browser-using-js-laravel-8/">Record &#038; upload video from browser using JS &#038; Laravel-8</a> appeared first on <a href="https://nikhilpatel.in">Nikhil Patel</a>.</p>
]]></description>
										<content:encoded><![CDATA[
		<div id="fws_6a1fa87823bc7"  data-column-margin="default" data-midnight="dark"  class="wpb_row vc_row-fluid vc_row top-level standard_section "  style="padding-top: 0px; padding-bottom: 0px; "><div class="row-bg-wrap" data-bg-animation="none" data-bg-overlay="false"><div class="inner-wrap"><div class="row-bg"  style=""></div></div><div class="row-bg-overlay" ></div></div><div class="row_col_wrap_12 col span_12 dark left">
	<div  class="vc_col-sm-12 wpb_column column_container vc_column_container col no-extra-padding inherit_tablet inherit_phone "  data-t-w-inherits="default" data-bg-cover="" data-padding-pos="all" data-has-bg-color="false" data-bg-color="" data-bg-opacity="1" data-hover-bg="" data-hover-bg-opacity="1" data-animation="" data-delay="0" >
		<div class="vc_column-inner" ><div class="column-bg-overlay-wrap" data-bg-animation="none"><div class="column-bg-overlay"></div></div>
			<div class="wpb_wrapper">
				<div id="fws_6a1fa87826e50" data-midnight="" data-column-margin="default" class="wpb_row vc_row-fluid vc_row inner_row standard_section   "  style="padding-top: 0px; padding-bottom: 0px; "><div class="row-bg-wrap"> <div class="row-bg" ></div> </div><div class="row_col_wrap_12_inner col span_12  left">
	<div  class="vc_col-sm-12 wpb_column column_container vc_column_container col child_column no-extra-padding inherit_tablet inherit_phone "   data-t-w-inherits="default" data-bg-cover="" data-padding-pos="all" data-has-bg-color="false" data-bg-color="" data-bg-opacity="1" data-hover-bg="" data-hover-bg-opacity="1" data-animation="" data-delay="0">
		<div class="vc_column-inner" ><div class="column-bg-overlay-wrap" data-bg-animation="none"><div class="column-bg-overlay"></div></div>
		<div class="wpb_wrapper">
			
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Hello Folks, we are back with something very interesting topic. Today we are going to learn how we can record and upload the video to the server from the browser using Js &amp; Laravel-8. So lest’s start.</p>
<p>If you are new and don’t know how to setup laravel then don’t worry you can start from scratch by clicking this link <a href="https://nikhilpatel.in/laravel-8-simple-crud-app/" target="_blank" rel="noopener">Laravel Setup &amp; Simple CRUD App.</a></p>
<p>In this demo, we are going to use JS and Laravel-8 and also we will user Ajax to upload a recorded video. Let’s get started step by step.<br />
<em>Note: we are not going to show how to set up laravel here so you can check out our  post <a href="https://nikhilpatel.in/laravel-8-simple-crud-app/" target="_blank" rel="noopener">Laravel Setup &amp; Simple CRUD App</a></em></p>
	</div>
</div>




<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>After installing laravel just follow these steps.</p>
	</div>
</div>




<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 1: Migration &amp; Routing</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>We will create Model, Controller in a single command</p>
<pre><code class="language-nginx"> artisan make:model Media -mcr </code></pre>
<p>A migration file will be created in the database/migrations directory, and we need to create our schema. I added file_name (text) column. I used $table-&gt;timestamps(); it will set created_at and updated_at automatically.<br />
Then run the migration command. And also don’t forget to add <strong>file_name </strong> in <strong>App\Models\Media.php</strong> fillable.</p>
<pre><code class="language-nginx">php artisan migrate</code></pre>
<p>So we have to set a resource route in <strong> routes/web.php </strong></p>
<pre><code class="language-php-extras">use App\Http\Controllers\MediaController;</code></pre>
<p>At top of <strong>routes/web.php</strong> and add following line after that.</p>
<pre><code class="language-php-extras">Route::resource('videos', MediaController::class); </code></pre>
<p>We already learned how to set views and layout in the previous post if you haven’t then just check checkout by clicking this link <a href="https://nikhilpatel.in/laravel-8-simple-crud-app/" target="_blank" rel="noopener">Laravel Setup &amp; Simple CRUD App.</a></p>
<p>Now move to the listing page <strong>index.blade.php</strong> in this you can see a listing of all videos and also have a delete option.</p>
	</div>
</div>



<div class="img-with-aniamtion-wrap " data-max-width="100%" data-max-width-mobile="default" data-border-radius="none" data-shadow="none" data-animation="fade-in" >
      <div class="inner">
        <div class="hover-wrap" data-hover-animation="none"> 
          <div class="hover-wrap-inner">
            <img fetchpriority="high" decoding="async" class="img-with-animation skip-lazy " data-delay="0" height="657" width="1347" data-animation="fade-in" src="https://nikhilpatel.in/wp-content/uploads/2021/09/App-Name-Video-Record-save-to-db.jpg" alt="Record &amp; upload video from browser using JS &amp; Laravel-8" srcset="https://nikhilpatel.in/wp-content/uploads/2021/09/App-Name-Video-Record-save-to-db.jpg 1347w, https://nikhilpatel.in/wp-content/uploads/2021/09/App-Name-Video-Record-save-to-db-300x146.jpg 300w, https://nikhilpatel.in/wp-content/uploads/2021/09/App-Name-Video-Record-save-to-db-1024x499.jpg 1024w, https://nikhilpatel.in/wp-content/uploads/2021/09/App-Name-Video-Record-save-to-db-768x375.jpg 768w" sizes="(min-width: 1450px) 75vw, (min-width: 1000px) 85vw, 100vw" />
          </div>
        </div>
      </div>
    </div>
<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 2: The HTML</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Now we had added 2 video tags one for show recording and another one will show your recorded clip preview.</p>
<p>There is a start button from where you can start recording. Stop button to stop recording, Save button to save the video to the table, and upload the video file to the server.Download the button for recorded video download.</p>
<p>Ideally, these elements aren&#8217;t created until it&#8217;s confirmed that The client supports video/camera, but for the sake of illustrating the elements involved, they are created with markup (not JavaScript).</p>
<p>Here the preview will be hidden until video recording stoped.<br />
<script src="https://gist.github.com/nikhilpatel8000/3b064de6393701e161e9c2f9c0b656bb.js"></script></p>
	</div>
</div>




<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 3: The JavaScript &amp; Access the camera interactively</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Modern browsers can have a direct line to the camera allowing us to build experiences that are fully integrated with the web page and the user will never leave the browser.</p>
<p><strong>Acquire access to the camera :</strong> <strong>navigator.mediaDevices.getUserMedia</strong>, a simple method sets the<strong>video </strong> element&#8217;s <strong>src</strong> to the user&#8217;s live camera/webcam. Calling the <strong>start</strong> method of the video then starts the element&#8217;s live streaming video connection. That&#8217;s all that&#8217;s required to connect your camera to the browser! Here we are going to record the only video so the audio parameter will be false.</p>
<pre><code>navigator.mediaDevices.getUserMedia({
	video: true,
	audio: false
})</code></pre>
<p>Here we had set a time limit for 5 seconds so video recording automatically will be stopped after 5 seconds. You can change as per your requirement, you have to do is just pass duration in milliseconds like 5000 for 5 seconds.</p>
<p>So we have set <strong>console.log</strong> to track all the activity of the recording task.</p>
	</div>
</div>




<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 4: Show the streaming blob</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>A blob is a data type that can store binary data. This is different than most other data types used in databases, such as integers, floating-point numbers, characters, and strings, which store letters and numbers.</p>
<p>Since blobs can store binary data, they can be used to store images or other multimedia files. For example, a photo album could be stored in a database using a blob data type for the images, and a string data type for the captions. Because blobs are used to store objects such as images, audio files, and video clips, they often require significantly more space than other data types.</p>
<p>after the recording stopped we need to set a preview so the user can watch the recorded video he can download or upload to the server.</p>
<p>finally how our recording script looks like.</p>
<p><script src="https://gist.github.com/nikhilpatel8000/e205c612a0d11db3d71a098aacefaf46.js"></script></p>
	</div>
</div>




<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 5: To upload the blob(video) to the server(Laravel-8)</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>As shown above we had set <strong>form object</strong> to append all the data and then we passed data to the controller. Note that since we passing media objects we need to use the POST method so it&#8217;s required CSRF TOKEN for submit data. So we can set CSRF TOKEN to the meta tag so we can use it anywhere on laravel website.</p>
<pre><code>&lt;meta name="csrf-token" content="{{csrf_token()}}"&gt;</code></pre>
<pre><code>document.querySelector('meta[name="csrf-token"]').getAttribute('content')</code></pre>
<p>Now we have to upload the video file to the server. So we need a directory where all the uploaded videos will be moved. We are using storage to move the file so we need to link storage.<br />
Run the following command to link storage</p>
<pre><code>php artisan storage:link</code></pre>
<p>You will see the <strong>storage</strong> directory like a shortcut icon in your public folder. Now just need to add the directory name and, it will create if that directory not exists and move the uploaded file to the server.</p>
<p>So finally how our App\Http\Controllers\MediaController.php looks like:</p>
<p><script src="https://gist.github.com/nikhilpatel8000/6db17184a181cbee06799538d777c57a.js"></script></p>
<p>Of course, you could add some Audio, Image, and GIF from Browser but I&#8217;ll save that for another post. For now, however, simply accessing the camera in our browser moves us miles ahead. Have fun recording videos within your browser!</p>
	</div>
</div>




		</div> 
	</div>
	</div> 
</div></div>
			</div> 
		</div>
	</div> 
</div></div>
<p>The post <a href="https://nikhilpatel.in/record-upload-video-from-browser-using-js-laravel-8/">Record &#038; upload video from browser using JS &#038; Laravel-8</a> appeared first on <a href="https://nikhilpatel.in">Nikhil Patel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nikhilpatel.in/record-upload-video-from-browser-using-js-laravel-8/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Laravel-8 Simple CRUD App</title>
		<link>https://nikhilpatel.in/laravel-8-simple-crud-app/</link>
					<comments>https://nikhilpatel.in/laravel-8-simple-crud-app/#comments</comments>
		
		<dc:creator><![CDATA[Nikhil Patel]]></dc:creator>
		<pubDate>Sat, 18 Sep 2021 11:44:00 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[blade]]></category>
		<category><![CDATA[boostrap]]></category>
		<category><![CDATA[composer]]></category>
		<category><![CDATA[laravel]]></category>
		<category><![CDATA[Php]]></category>
		<guid isPermaLink="false">https://nikhilpatel.in/?p=409</guid>

					<description><![CDATA[<p>The post <a href="https://nikhilpatel.in/laravel-8-simple-crud-app/">Laravel-8 Simple CRUD App</a> appeared first on <a href="https://nikhilpatel.in">Nikhil Patel</a>.</p>
]]></description>
										<content:encoded><![CDATA[
		<div id="fws_6a1fa8782cb07"  data-column-margin="default" data-midnight="dark"  class="wpb_row vc_row-fluid vc_row standard_section "  style="padding-top: 0px; padding-bottom: 0px; "><div class="row-bg-wrap" data-bg-animation="none" data-bg-overlay="false"><div class="inner-wrap"><div class="row-bg"  style=""></div></div><div class="row-bg-overlay" ></div></div><div class="row_col_wrap_12 col span_12 dark left">
	<div  class="vc_col-sm-12 wpb_column column_container vc_column_container col no-extra-padding inherit_tablet inherit_phone "  data-t-w-inherits="default" data-bg-cover="" data-padding-pos="all" data-has-bg-color="false" data-bg-color="" data-bg-opacity="1" data-hover-bg="" data-hover-bg-opacity="1" data-animation="" data-delay="0" >
		<div class="vc_column-inner" ><div class="column-bg-overlay-wrap" data-bg-animation="none"><div class="column-bg-overlay"></div></div>
			<div class="wpb_wrapper">
				<div id="fws_6a1fa8782d0ff" data-midnight="" data-column-margin="default" class="wpb_row vc_row-fluid vc_row inner_row standard_section   "  style="padding-top: 0px; padding-bottom: 0px; "><div class="row-bg-wrap"> <div class="row-bg" ></div> </div><div class="row_col_wrap_12_inner col span_12  left">
	<div  class="vc_col-sm-12 wpb_column column_container vc_column_container col child_column no-extra-padding inherit_tablet inherit_phone "   data-t-w-inherits="default" data-bg-cover="" data-padding-pos="all" data-has-bg-color="false" data-bg-color="" data-bg-opacity="1" data-hover-bg="" data-hover-bg-opacity="1" data-animation="" data-delay="0">
		<div class="vc_column-inner" ><div class="column-bg-overlay-wrap" data-bg-animation="none"><div class="column-bg-overlay"></div></div>
		<div class="wpb_wrapper">
			
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Hello Folks, we are here with something very interesting topic for php fans. Today we will see a simple CRUD in laravel.</p>
<p>Laravel is a web application framework with an expressive, elegant syntax. Laravel Is MVC(Model View Controller) architecture.</p>
<p>Laravel has a large and growing community which makes it easy for new developers to find solutions and help with challenges. Laravel releases a new version twice in a year, and the latest version which is Laravel 8 was released on the 8th Sept 2020.</p>
<p>This article will help you to create basic CRUD in laravel. Don&#8217;t worry if you are a beginner we will start from scratch. Laravel has many inbuilt functionalities ready to use which makes laravel a magical framework.</p>
	</div>
</div>




<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>A couple of things you need to have in your system before starting.</p>
	</div>
</div>



<div class="nectar-fancy-ul" data-list-icon="steadysets-icon-arrow-right" data-animation="false" data-animation-delay="0" data-color="accent-color" data-spacing="default" data-alignment="left"> 
<ul>
<li>Composer</li>
<li>PHP</li>
<li>Server (WAMP, XAMPP)</li>
</ul>
 </div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Here we are going to use MySQL. So if you have wamp or xampp then you don&#8217;t need to do anything additional.</p>
<p>You must require a composer in your system. Now the question is what is the composer. In short, a Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.</p>
<p>We will learn more about the composer in the next post. Now you can install the composer by <a href="https://getcomposer.org/download/" target="_blank" rel="noopener">clicking here</a>.</p>
<p>Moving forward to laravel-8 simple CRUD app we will go step by step so it makes it more easy and understandable.</p>
	</div>
</div>




<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 1: Install Laravel</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Go to you command prompt and run the following command :</p>
<pre><code class="language-nginx">composer create-project laravel/laravel=8.0 laravel_crud</code></pre>
<p>It will take a few minutes depending on your internet speed. It will download the laravel framework and required dependencies.</p>
	</div>
</div>



<div class="img-with-aniamtion-wrap " data-max-width="100%" data-max-width-mobile="default" data-border-radius="none" data-shadow="none" data-animation="fade-in" >
      <div class="inner">
        <div class="hover-wrap" data-hover-animation="none"> 
          <div class="hover-wrap-inner">
            <img decoding="async" class="img-with-animation skip-lazy " data-delay="0" height="269" width="1116" data-animation="fade-in" src="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-1.png" alt="Laravel-8 Simple CRUD App" srcset="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-1.png 1116w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-1-300x72.png 300w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-1-1024x247.png 1024w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-1-768x185.png 768w" sizes="(min-width: 1450px) 75vw, (min-width: 1000px) 85vw, 100vw" />
          </div>
        </div>
      </div>
    </div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Using this command you don&#8217;t need to copy .env.example to .env and also you don&#8217;t need to generate APP_KEY this is a new version of larave</p>
	</div>
</div>



<div class="img-with-aniamtion-wrap " data-max-width="100%" data-max-width-mobile="default" data-border-radius="none" data-shadow="none" data-animation="fade-in" >
      <div class="inner">
        <div class="hover-wrap" data-hover-animation="none"> 
          <div class="hover-wrap-inner">
            <img decoding="async" class="img-with-animation skip-lazy " data-delay="0" height="325" width="978" data-animation="fade-in" src="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-2.png" alt="" srcset="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-2.png 978w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-2-300x100.png 300w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-2-768x255.png 768w" sizes="(min-width: 1450px) 75vw, (min-width: 1000px) 85vw, 100vw" />
          </div>
        </div>
      </div>
    </div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>After a successful full install, you will see a message. And Larave APP is ready.</p>
<p>Run command in your terminal</p>
<pre><code class="language-nginx"> php artisan serv</code></pre>
<p>You will see the following message.</p>
<p><code>Starting Laravel development server: http://127.0.0.1:8000</code></p>
<p>Now run 127.0.0.1:8000 in your browser you will see laravel landing page</p>
	</div>
</div>



<div class="img-with-aniamtion-wrap " data-max-width="100%" data-max-width-mobile="default" data-border-radius="none" data-shadow="none" data-animation="fade-in" >
      <div class="inner">
        <div class="hover-wrap" data-hover-animation="none"> 
          <div class="hover-wrap-inner">
            <img loading="lazy" decoding="async" class="img-with-animation skip-lazy " data-delay="0" height="575" width="1238" data-animation="fade-in" src="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-3.png" alt="" srcset="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-3.png 1238w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-3-300x139.png 300w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-3-1024x476.png 1024w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-3-768x357.png 768w" sizes="auto, (min-width: 1450px) 75vw, (min-width: 1000px) 85vw, 100vw" />
          </div>
        </div>
      </div>
    </div>
<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 2: Database setup</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Open PHPMyAdmin and create a new database. My database name is laravel_crud</p>
<p>Open the .env file on your IDE or text editor</p>
<pre><code class="language-php-extras">DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_crud
DB_USERNAME=root
DB_PASSWORD=</code></pre>
<p>Change the DB_DATABASE to the name of your database and if you have set a username and password for your PHPMyAdmin, specify it, otherwise, leave the username as root and password blank.</p>
	</div>
</div>




<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 3: Creating Migration</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Before moving forward you need to know about laravel migrations.</p>
<p>Migrations are like version control for your database, allowing your team to modify and share the application&#8217;s database schema. Migrations are typically paired with Laravel&#8217;s schema builder to build your application&#8217;s database schema.</p>
<p>If you have ever had to tell a teammate to manually add a column to their local database schema, you&#8217;ve faced the problem that database migrations solve.<br />
you can read more about migration by <a href="https://laravel.com/docs/8.x/migrations" target="_blank" rel="noopener">clicking this link</a>.</p>
<p>I will elaborate on it in the next post. Now we will continue to CRUD.</p>
<p>You can see migration files in the following path :</p>
<p><code>\database\migrations</code></p>
	</div>
</div>



<div class="img-with-aniamtion-wrap " data-max-width="100%" data-max-width-mobile="default" data-border-radius="none" data-shadow="none" data-animation="fade-in" >
      <div class="inner">
        <div class="hover-wrap" data-hover-animation="none"> 
          <div class="hover-wrap-inner">
            <img loading="lazy" decoding="async" class="img-with-animation skip-lazy " data-delay="0" height="367" width="780" data-animation="fade-in" src="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-5.png" alt="" srcset="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-5.png 780w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-5-300x141.png 300w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-5-768x361.png 768w" sizes="auto, (min-width: 1450px) 75vw, (min-width: 1000px) 85vw, 100vw" />
          </div>
        </div>
      </div>
    </div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Laravel gives default migration for the user, password reset &amp; jobs</p>
<p>You can create different migrations as per your requirement. Now we are creating migration for the product table. So go to the terminal or Command prompt and write the following command. there is a quick twist. To create migration we need to run the following command</p>
<pre><code class="language-powershell">php artisan make:migration create_products_table --create=products</code></pre>
<p>But we have to create Models &amp; controller so we will create migration , model &amp; controller by using one command :</p>
<pre><code class="language-powershell">php artisan make:model Product -mcr</code></pre>
	</div>
</div>



<div class="img-with-aniamtion-wrap " data-max-width="100%" data-max-width-mobile="default" data-border-radius="none" data-shadow="none" data-animation="fade-in" >
      <div class="inner">
        <div class="hover-wrap" data-hover-animation="none"> 
          <div class="hover-wrap-inner">
            <img loading="lazy" decoding="async" class="img-with-animation skip-lazy " data-delay="0" height="123" width="697" data-animation="fade-in" src="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-6.png" alt="Laravel-8 Simple CRUD App" srcset="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-6.png 697w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-6-300x53.png 300w" sizes="auto, (min-width: 1450px) 75vw, (min-width: 1000px) 85vw, 100vw" />
          </div>
        </div>
      </div>
    </div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>You can see 3 files created in your project.</p>
	</div>
</div>



<div class="img-with-aniamtion-wrap " data-max-width="100%" data-max-width-mobile="default" data-border-radius="none" data-shadow="none" data-animation="fade-in" >
      <div class="inner">
        <div class="hover-wrap" data-hover-animation="none"> 
          <div class="hover-wrap-inner">
            <img loading="lazy" decoding="async" class="img-with-animation skip-lazy " data-delay="0" height="632" width="778" data-animation="fade-in" src="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-7.png" alt="Laravel-8 Simple CRUD App" srcset="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-7.png 778w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-7-300x244.png 300w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-7-768x624.png 768w" sizes="auto, (min-width: 1450px) 75vw, (min-width: 1000px) 85vw, 100vw" />
          </div>
        </div>
      </div>
    </div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>A migration file will be created in the database/migrations folder, and we need to create our schema. I added name (string), description(text), sku(string), price (float).</p>
<p>I used $table-&gt;timestamps(); it will set created_at and updated_at automatically.</p>
<pre><code class="language-php">use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table-&gt;bigIncrements('id');
            $table-&gt;string('name')-&gt;nullable();
            $table-&gt;text('description')-&gt;nullable();
            $table-&gt;decimal('product_price', 12, 2)-&gt;default(0);
            $table-&gt;timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
}</code></pre>
<p>Before we run our migration command, we need to set the default string length, else, we are going to run into errors So go to</p>
<p><code>app/Providers/AppServiceProvider.php</code></p>
<pre><code class="language-php">/**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }</code></pre>
<p>to the boot function, also add At the top</p>
<pre><code class="language-php">namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;</code></pre>
<p>Finally, we run our migration command</p>
<pre><code class="language-powershell">php artisan migrate</code></pre>
	</div>
</div>



<div class="img-with-aniamtion-wrap " data-max-width="100%" data-max-width-mobile="default" data-border-radius="none" data-shadow="none" data-animation="fade-in" >
      <div class="inner">
        <div class="hover-wrap" data-hover-animation="none"> 
          <div class="hover-wrap-inner">
            <img loading="lazy" decoding="async" class="img-with-animation skip-lazy " data-delay="0" height="264" width="680" data-animation="fade-in" src="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-10.png" alt="Laravel-8 Simple CRUD App" srcset="https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-10.png 680w, https://nikhilpatel.in/wp-content/uploads/2021/09/larave-crud-10-300x116.png 300w" sizes="auto, (min-width: 1450px) 75vw, (min-width: 1000px) 85vw, 100vw" />
          </div>
        </div>
      </div>
    </div>
<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 4: Add Resource Route</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>We need to add routes for our CRUD operations, Laravel provides a resource route for us that will take care of the CRUD, that is a route to Create, another route to Retrieve, a separate route to Update, and finally a route to Delete.</p>
<p>So head up to <strong>routes\web.php</strong> and add our resource route</p>
<pre><code class="language-php"> Route::resource(‘products’, ProductController::class); </code></pre>
<p><strong>ProductController::class</strong> this was introduced in this version, Laravel 8 does not know where to call the function from<br />
<strong>use App\Http\Controllers\ProductController&#8217;</strong></p>
<pre><code class="language-php-extras">use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ProductController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::resource('products', ProductController::class);</code></pre>
	</div>
</div>




<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 5: Controller and Model</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>You can find the following methods in the controller folder<br />
<strong>app/Http/Controllers/ProjectController.php<br />
</strong></p>
	</div>
</div>



<div class="nectar-fancy-ul" data-list-icon="steadysets-icon-arrow-right" data-animation="false" data-animation-delay="0" data-color="accent-color" data-spacing="default" data-alignment="left"> 
<ul>
<li>index()
<ul>
<li>This method is used for display listing or landing view.</li>
</ul>
</li>
<li>create()
<ul>
<li>this methods used for show create form</li>
</ul>
</li>
<li>store(Request, $request)
<ul>
<li>This method used for store data to the table</li>
</ul>
</li>
<li>show(Product, $product)
<ul>
<li>This method use to show records details</li>
</ul>
</li>
<li>edit(Product, $product)
<ul>
<li>This method used to show edit form with filled data to inputs.</li>
</ul>
</li>
<li>update(Request, $request, Product, $product)
<ul>
<li>This method is used to update records.</li>
</ul>
</li>
<li>destroy( Product, $product)
<ul>
<li>This method is used to delete records from the table.</li>
</ul>
</li>
</ul>
 </div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>I had mentioned the basic use of all resource methods. We will see each method in the future in this post.<br />
Laravel 8 has created a folder called Models, which is not available in the previous version, so our project model is found in the <strong>app/Models/Product.php </strong></p>
<p>You need to add fillable to insert column value in DB. We create a method of the model so we need to specify which column should be created.</p>
<p><strong>app/Models/Product.php</strong></p>
<pre><code class="language-php">namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use HasFactory;
    public $timestamps = true;

    protected $fillable = [
        'name',
        'description',
        'product_price',
    ];
}</code></pre>
	</div>
</div>




<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 6: Add your views</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Now move to the front end views. Larvel has a blade file structure for frontend. It&#8217;s necessary to follow the directory structure to interact with our app easily. So we will manage by the following structure.</p>
	</div>
</div>



<div class="nectar-fancy-ul" data-list-icon="steadysets-icon-arrow-right" data-animation="false" data-animation-delay="0" data-color="accent-color" data-spacing="default" data-alignment="left"> 
<ul>
<li>Layouts
<ul>
<li>app.blade.php</li>
</ul>
</li>
<li>products
<ul>
<li>Index.blade.php</li>
<li>Create.blade.php</li>
<li>Edit.blade.php</li>
<li>show.blade.php</li>
</ul>
</li>
</ul>
 </div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>If we are creating another module then we can add a new dir and put all the blade files in that folder so it looks clean and easy to manage.</p>
<p>But we will create a <strong>form.blade</strong> file so we no need to manage to create &amp; edit separate files.</p>
	</div>
</div>



<div class="nectar-fancy-ul" data-list-icon="steadysets-icon-arrow-right" data-animation="false" data-animation-delay="0" data-color="accent-color" data-spacing="default" data-alignment="left"> 
<ul>
<li>products
<ul>
<li>Index.blade.php</li>
<li>form.blade.php</li>
<li>show.blade.php</li>
</ul>
</li>
</ul>
 </div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Here <strong>\resources\views\layout\app.blade.php </strong> looks like this</p>
<pre><code class="language-php">&lt;html&gt;

&lt;head&gt;
    &lt;title&gt;App Name - @yield('title')&lt;/title&gt;

    &lt;!-- Bootstrap --&gt;
    &lt;link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css" rel="stylesheet"&gt;

    &lt;style&gt;
        .pagination{
            display: block;
        }
        .pagination nav{display: block;}
        .pagination nav .rounded-md svg{width: 10px;}
    &lt;/style&gt;

    &lt;!-- Font Awesome JS --&gt;
    &lt;script defer src="https://use.fontawesome.com/releases/v5.0.13/js/solid.js"
        integrity="sha384-tzzSw1/Vo+0N5UhStP3bvwWPq+uvzCMfrN1fEFe+xBmv1C/AtVX5K0uZtmcHitFZ" crossorigin="anonymous"&gt;
    &lt;/script&gt;
    &lt;script defer src="https://use.fontawesome.com/releases/v5.0.13/js/fontawesome.js"integrity="sha384-6OIrr52G08NpOFSZdxxz1xdNSndlD4vdcf/q2myIUVO0VsqaGHJsB0RaBE01VTOY" crossorigin="anonymous"&gt;
    &lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;

    &lt;div class="container"&gt;
        @yield('content')
    &lt;/div&gt;

&lt;/body&gt;

&lt;/html&gt;
</code></pre>
<p>We need to create index.blade.php in the product folder. Need to extend the layout file. We created <strong>\resources\views\layout\app.blade.php </strong> file and it will be the base of all views. Here we can set css and js</p>
<p>You can find we have added some css for pagination. Now move to <strong>resources\views\products\index.blade.php</strong> file you can find there is a table which has a listing of products and also has an action to edit, view, delete.</p>
<p>Move to <strong>app\Http\Controllers\ProductController.php</strong> you can find <strong>index()</strong> for render view and data.</p>
<p><strong>app\Http\Controllers\ProductController.php</strong></p>
<pre><code class="language-php">/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
         $products = Product::latest()-&gt;paginate(5);

        return view('products.index', compact('products'))
            -&gt;with('i', (request()-&gt;input('page', 1) - 1) * 5);
    }</code></pre>
<p>Here we had added pagination(5). Laravel provides inbuilt pagination features. Just we need to put pagination() and pass the number of rows you want and do nothing. For display pagination, we need to set</p>
<pre><code class="language-php">$products-&gt;links()</code></pre>
<p>It will show all page numbers with next &amp; previous navigation.</p>
<p>Now you can find a button beside the Laravel 8 crud title. From here we can navigate to add product form.</p>
<pre><code class="language-http"> &lt;a class="btn btn-success" href="{{ route('products.create') }}" title="Create a product"&gt; &lt;i class="fas fa-plus-circle"&gt;&lt;/i&gt;
                    &lt;/a&gt;</code></pre>
<p><strong>app\Http\Controllers\ProductController.php<br />
</strong></p>
<pre><code class="language-php">/**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('products.form');
    }
</code></pre>
<p>When we click on the button we redirect to the create form wish is our <strong>resources\views\products\form.blade.php</strong></p>
<pre><code class="language-php">@extends('layouts.app')

@section('content')
    &lt;div class="row"&gt;
        &lt;div class="col-lg-12 margin-tb" style="margin-top:50px;"&gt;
            &lt;div class="pull-left"&gt;
            &lt;h2&gt;{{(isset($product)) ? 'Edit' : 'Add New'}}  Product&lt;/h2&gt;
            &lt;/div&gt;
            &lt;div class="pull-right"&gt;
                &lt;a class="btn btn-primary" href="{{ route('products.index') }}" title="Go back"&gt; &lt;i class="fas fa-backward "&gt;&lt;/i&gt; &lt;/a&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    @if ($errors-&gt;any())
        &lt;div class="alert alert-danger"&gt;
            &lt;strong&gt;Whoops!&lt;/strong&gt; There were some problems with your input.&lt;br&gt;&lt;br&gt;
            &lt;ul&gt;
                @foreach ($errors-&gt;all() as $error)
                    &lt;li&gt;{{ $error }}&lt;/li&gt;
                @endforeach
            &lt;/ul&gt;
        &lt;/div&gt;
    @endif
    &lt;form action="{{ (isset($product)) ? route('products.update', $product-&gt;id) : route('products.store') }}" method="POST" &gt;
        @csrf
        @if(isset($product))
            @method('PUT')
        @endif

        &lt;div class="row"&gt;
            &lt;div class="col-xs-12 col-sm-12 col-md-12"&gt;
                &lt;div class="form-group"&gt;
                    &lt;strong&gt;Name:&lt;/strong&gt;
                    @php
                        $name = (old('name')) ? old('name') : ((isset($product-&gt;name)) ? $product-&gt;name : '');
                    @endphp
                    &lt;input type="text" name="name" class="form-control" placeholder="Name" value="{{$name}}"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="col-xs-12 col-sm-12 col-md-12"&gt;
                &lt;div class="form-group"&gt;
                    &lt;strong&gt;Description:&lt;/strong&gt;
                    @php
                        $description = (old('description')) ? old('description') : ((isset($product-&gt;description)) ? $product-&gt;description : '');
                    @endphp
                    &lt;textarea class="form-control" style="height:50px" name="description" placeholder="description"&gt;{{$description}}&lt;/textarea&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="col-xs-12 col-sm-12 col-md-12"&gt;
                &lt;div class="form-group"&gt;
                    &lt;strong&gt;Price:&lt;/strong&gt;
                    @php
                        $price = (old('product_price')) ? old('product_price') : ((isset($product-&gt;product_price)) ? $product-&gt;product_price : '');
                    @endphp
                    &lt;input type="number" name="product_price" class="form-control" placeholder="price" value="{{$price}}"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="col-xs-12 col-sm-12 col-md-12 text-center"&gt;
                &lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/form&gt;
@endsection
</code></pre>
<p>This form used for add and edit as well. So we have passed the <strong>$product</strong> from the controller. You will find an edit function of the controller.</p>
<p><strong>app\Http\Controllers\ProductController.php</strong></p>
<pre><code class="language-php">/**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\Product  $product
     * @return \Illuminate\Http\Response
     */
    public function edit(Product $product)
    {
        return view('products.form', compact('product'));
    }</code></pre>
<p>It&#8217;s for code reusability. If there is a large number of fields and complex forms then we can use a separate view for the edit to avoid complexity.</p>
<p>Now move to the <strong>resources\views\products\show.blade.php </strong> Here we had shown details of the product is quite simple and easy. We have passed the project object from the controller.</p>
<p><strong>app\Http\Controllers\ProductController.php</strong></p>
<pre><code class="language-php">/**
     * Display the specified resource.
     *
     * @param  \App\Models\Product  $product
     * @return \Illuminate\Http\Response
     */
    public function show(Product $product)
    {
        return view('products.show', compact('product'));
    }</code></pre>
<p><strong>resources\views\products\show.blade.php</strong></p>
<pre><code class="language-php">@extends('layouts.app')


@section('content')
    &lt;div class="row"&gt;
        &lt;div class="col-lg-12 margin-tb" style="margin-top:50px;"&gt;
            &lt;div class="pull-left"&gt;
                &lt;h2&gt;  {{ $product-&gt;name }}&lt;/h2&gt;
            &lt;/div&gt;
            &lt;div class="pull-right"&gt;
                &lt;a class="btn btn-primary" href="{{ route('products.index') }}" title="Go back"&gt; &lt;i class="fas fa-backward "&gt;&lt;/i&gt; &lt;/a&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div class="row"&gt;
        &lt;div class="col-xs-12 col-sm-12 col-md-12"&gt;
            &lt;div class="form-group"&gt;
                &lt;strong&gt;Name:&lt;/strong&gt;
                {{ $product-&gt;name }}
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="col-xs-12 col-sm-12 col-md-12"&gt;
            &lt;div class="form-group"&gt;
                &lt;strong&gt;Description:&lt;/strong&gt;
                {{ $product-&gt;description }}
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="col-xs-12 col-sm-12 col-md-12"&gt;
            &lt;div class="form-group"&gt;
                &lt;strong&gt;Price:&lt;/strong&gt;
                {{ $product-&gt;price }}
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="col-xs-12 col-sm-12 col-md-12"&gt;
            &lt;div class="form-group"&gt;
                &lt;strong&gt;Date Created:&lt;/strong&gt;
                {{ date_format($product-&gt;created_at, 'jS M Y') }}
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
@endsection
</code></pre>
	</div>
</div>




<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 6: Add your views</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>So basically we need to pass data to the controller Store method.</p>
<p>In this method we have to do backend validation. Click here to know more about laravel validation <a href="https://laravel.com/docs/8.x/validation" target="_blank" rel="noopener">by clicking this link</a></p>
<p>When we submit the form data will be passed to the store method of ProductController. Here the first request will be validated, if data passes the validation then it will store it to the table.</p>
<pre><code class="language-php">/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request-&gt;validate([
            'name' =&gt; 'required',
            'description' =&gt; 'required',
            'product_price' =&gt; 'required'
        ]);

        Product::create($request-&gt;all());

        return redirect()-&gt;route('products.index')
            -&gt;with('success', 'Product created successfully.');
    }</code></pre>
<p>Same for the update function but we have to pass the object of the product model and it will update that row.</p>
<pre><code class="language-php">/**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Product  $product
     * @return \Illuminate\Http\Response
     */
    public function destroy(Product $product)
    {
        $product-&gt;delete();

        return redirect()-&gt;route('products.index')
            -&gt;with('success', 'Product deleted successfully');
    }</code></pre>
<p>We need to pass the object of the Product modal and it will delete that record that’s it.</p>
<p>So now ProductController looks like this.</p>
<pre><code class="language-php">&lt;?php

namespace App\Http\Controllers;

use App\Models\Product;
use Illuminate\Http\Request;

class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
         $products = Product::latest()-&gt;paginate(5);

        return view('products.index', compact('products'))
            -&gt;with('i', (request()-&gt;input('page', 1) - 1) * 5);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('products.form');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request-&gt;validate([
            'name' =&gt; 'required',
            'description' =&gt; 'required',
            'product_price' =&gt; 'required'
        ]);

        Product::create($request-&gt;all());

        return redirect()-&gt;route('products.index')
            -&gt;with('success', 'Product created successfully.');
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Product  $product
     * @return \Illuminate\Http\Response
     */
    public function show(Product $product)
    {
        return view('products.show', compact('product'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\Product  $product
     * @return \Illuminate\Http\Response
     */
    public function edit(Product $product)
    {
        return view('products.form', compact('product'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Product  $product
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Product $product)
    {
       $request-&gt;validate([
            'name' =&gt; 'required',
            'description' =&gt; 'required',
            'product_price' =&gt; 'required'
        ]);

        $product-&gt;update($request-&gt;all());

        return redirect()-&gt;route('products.index')
            -&gt;with('success', 'Product updated successfully');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Product  $product
     * @return \Illuminate\Http\Response
     */
    public function destroy(Product $product)
    {
        $product-&gt;delete();

        return redirect()-&gt;route('products.index')
            -&gt;with('success', 'Product deleted successfully');
    }
}
</code></pre>
<p>The whole demo project is available on <a href="http://GitHub" target="_blank" rel="noopener">GitHub</a> so that you can see the code in context.</p>
	</div>
</div>




		</div> 
	</div>
	</div> 
</div></div>
			</div> 
		</div>
	</div> 
</div></div>
<p>The post <a href="https://nikhilpatel.in/laravel-8-simple-crud-app/">Laravel-8 Simple CRUD App</a> appeared first on <a href="https://nikhilpatel.in">Nikhil Patel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nikhilpatel.in/laravel-8-simple-crud-app/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
