<?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>Laravel CRUD Operations Archives - Codeplaners</title>
	<atom:link href="https://codeplaners.com/tag/laravel-crud-operations/feed/" rel="self" type="application/rss+xml" />
	<link>https://codeplaners.com/tag/laravel-crud-operations/</link>
	<description>Code Solution</description>
	<lastBuildDate>Wed, 10 Mar 2021 09:43:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>

<image>
	<url>https://codeplaners.com/wp-content/uploads/2020/09/cropped-favicon-social-32x32.png</url>
	<title>Laravel CRUD Operations Archives - Codeplaners</title>
	<link>https://codeplaners.com/tag/laravel-crud-operations/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Laravel Framework CRUD Operations</title>
		<link>https://codeplaners.com/laravel-framework-crud-operations/</link>
					<comments>https://codeplaners.com/laravel-framework-crud-operations/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 10 Mar 2021 09:40:45 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Install laravel]]></category>
		<category><![CDATA[Laravel CRUD]]></category>
		<category><![CDATA[Laravel CRUD Operations]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=465</guid>

					<description><![CDATA[<p>Laravel Framework CRUD Operations, I will show you how to implement Operations crud example with Laravel. In this laravel crud example, you will learn how to implement the laravel crud (create, read, update and delete) . Laravel CRUD Operations Download Laravel Configure Database Create Migration, Model and Controller Add Routes In web.php Run Server Step &#8230; <a href="https://codeplaners.com/laravel-framework-crud-operations/" class="more-link">Continue reading<span class="screen-reader-text"> "Laravel Framework CRUD Operations"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-framework-crud-operations/">Laravel Framework CRUD Operations</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Laravel Framework CRUD Operations,  I will show you how to implement Operations crud example with Laravel.</p>
<p>In this laravel crud example, you will learn how to implement the laravel crud (create, read, update and delete) .</p>
<h3>Laravel CRUD Operations</h3>
<ul style="list-style: circle;padding: 0 0 0 16px;font-weight: 700;line-height: 26px;font-size: 16px;">
<li>Download Laravel</li>
<li>Configure Database</li>
<li>Create Migration, Model and Controller</li>
<li>Add Routes In web.php</li>
<li>Run Server</li>
</ul>
<h3>Step 1:- Download And Install Laravel</h3>
<pre class="brush: php; title: ; notranslate">composer create-project --prefer-dist laravel/laravel blog</pre>
<h3>Step 2:- Configure Database</h3>
<pre class="brush: php; title: ; notranslate">
DB_CONNECTION=mysql 
DB_HOST=127.0.0.1 
DB_PORT=3306 
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
</pre>
<h3>Step 3:- Create Migration, Model and Controller</h3>
<h3>Create Model</h3>
<pre class="brush: php; title: ; notranslate"> php artisan make:model Post -m </pre>
<h5>Add code in <b>database/migrations/create_posts_table.php</b></h5>
<pre class="brush: php; title: ; notranslate"> 
&lt;?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
			$table-&gt;bigIncrements('id');
			$table-&gt;string('title');
			$table-&gt;text('description');
			$table-&gt;timestamps();
		});
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
}
</pre>
<h5>Add Post table values in <b>app/Models/Post.php</b></h5>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $fillable = &#x5B;'title', 'description'];
}
</pre>
<h5>Migrate the database using the command</h5>
<pre class="brush: php; title: ; notranslate">php artisan migrate</pre>
<h3>Create Post Controller</h3>
<pre class="brush: php; title: ; notranslate">php artisan make:controller PostController</pre>
<h5>open PostController and define index, add, edit, delete methods in PostController.php, go to <b>app\Http\Controllers\PostController.php</b></h5>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace App\Http\Controllers;
use DB;
use Session;
use App\Models\Post;
use Illuminate\Http\Request;

class PostController extends Controller
{
    // all posts
    public function index()
    {
        $posts = Post::all();
        return view('post/index',compact('posts',$posts));
    }

	// post add
	public function AddPost(Request $request)
    {

        return view('post/add-post');
    }
	
	// post Store
	public function Store(Request $request){
        $this-&gt;validate($request, &#x5B;
            'title' =&gt; 'required|string|min:3|max:255',
            'description' =&gt; 'required',
        ]);

        $pages = new Post;

        $pages-&gt;title = $request&#x5B;'title'];
        $pages-&gt;description = $request&#x5B;'description'];
    
        $pages-&gt;save();
		
        Session::flash( 'message', 'Post published.' );
        return redirect('/post');
    }
	
	// post posteditshow
	public function PostShow($id)
    {
        $posts = DB::select('select * from posts where id = ?',&#x5B;$id]);
        return view('post/postedit',&#x5B;'posts'=&gt;$posts]);
    }

	// post Edit
	public function Postedit(Request $request,$id)
	{
		$request-&gt;validate(&#x5B;
			'title' =&gt; 'required',
		]);
		$update&#x5B;'title'] = $request-&gt;get('title');
		$update&#x5B;'description'] = $request-&gt;get('description');

		Post::where('id',$id)-&gt;update($update);

		$request-&gt;session()-&gt;flash('message', 'Successfully Updated!');
		return redirect('/post');

	}
	
	
	// post Delete
	 public function Delete(Request $request,$id)
	 {
	 	DB::delete('delete from posts where id = ?',&#x5B;$id]);

	 	$request-&gt;session()-&gt;flash('message', 'Successfully Delete!');
	 	return redirect('/post');
   	 }
	
}

</pre>
<h5>Step 4:- Add post folder in resources</h5>
<p>Create post folder this path <strong>resources\views</strong><br />
and post folder add file:</p>
<ul style="list-style: circle;padding: 0 0 0 16px;font-weight: 700;line-height: 26px;font-size: 16px;">
<li>index.blade.php</li>
<li>add-post.blade.php</li>
<li>postedit.blade.php</li>
</ul>
<p>Open <strong>index.blade.php</strong> file and update the code your file:-</p>
<pre class="brush: php; title: ; notranslate">
@extends('layouts.app')

@section('content')

      &lt;div class=&quot;bg-white table-responsive rounded shadow-sm pt-3 pb-3 mb-30&quot;&gt;
      	&lt;div&gt;&lt;a href=&quot;{{ url('add-post') }}&quot; class=&quot;btn&quot;&gt;Add Post&lt;/a&gt;&lt;/div&gt;
        @if(Session::has('message'))
        	&lt;p class=&quot;alert alert-info&quot; style=&quot;clear: both;&quot;&gt;{{ Session::get('message') }}&lt;/p&gt;
        @endif
        &lt;table id=&quot;data-table&quot; class=&quot;table mb-0 table-striped&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt;
            &lt;thead&gt;
                &lt;tr&gt;
                    &lt;th data-orderable=&quot;false&quot;&gt;Id&lt;/th&gt;
                    &lt;th&gt;Title&lt;/th&gt;
                    &lt;th&gt;Description&lt;/th&gt;
                    &lt;th width=&quot;270&quot;&gt;Action&lt;/th&gt;
                &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
                @foreach ($posts as $post)
                &lt;tr&gt;
                    &lt;td&gt;{{ $post-&gt;id }}&lt;/td&gt;
                    &lt;td&gt;{{ $post-&gt;title }}&lt;/td&gt;
                    &lt;td&gt;{{ $post-&gt;description }}&lt;/td&gt;
                    &lt;td&gt;&lt;a href=&quot;{{ url('postedit') }}/{{ $post-&gt;id }}&quot; class=&quot;btn&quot; style=&quot;float: left;&quot;&gt;Edit Post&lt;/a&gt;&lt;a href=&quot;postdelete/{{ $post-&gt;id }}&quot; class=&quot;btn&quot; style=&quot;background:#F30;&quot;&gt;Delete&lt;/a&gt;&lt;/td&gt;
                &lt;/tr&gt;
                @endforeach
            &lt;/tbody&gt;
        &lt;/table&gt;
    &lt;/div&gt;

@endsection


</pre>
<p>Open <strong>add-post.blade.php</strong> file and update the code your file:-</p>
<pre class="brush: php; title: ; notranslate">
@extends('layouts.app')

@section('content')

            &lt;div class=&quot;page-content&quot;&gt;
                    &lt;div class=&quot;container-fluid&quot;&gt;
                        &lt;div class=&quot;row&quot;&gt;
                            &lt;div class=&quot;col-lg-12&quot;&gt;
                                &lt;div class=&quot;portlet-box portlet-gutter ui-buttons-col mb-30&quot;&gt;
                                    &lt;div class=&quot;portlet-body&quot;&gt;
                                        &lt;form class=&quot;needs-validation&quot; method=&quot;post&quot;  action=&quot;{{ url('add-post') }}&quot; novalidate enctype=&quot;multipart/form-data&quot; &gt;
                                        &lt;input type = &quot;hidden&quot; name = &quot;_token&quot; value = &quot;&lt;?php echo csrf_token(); ?&gt;&quot;&gt;
                                            &lt;div class=&quot;form-row&quot;&gt;
                                                &lt;div class=&quot;col-md-12 mb-3&quot;&gt;
                                                    &lt;label for=&quot;validationCustom01&quot;&gt;Post Title&lt;/label&gt;
                                                    &lt;input type=&quot;text&quot; class=&quot;form-control&quot;  name=&quot;title&quot; placeholder=&quot;Page Title&quot; &gt;
                                                &lt;/div&gt;
                                                &lt;div class=&quot;col-md-12 mb-3&quot;&gt;
                                                    &lt;label for=&quot;image&quot;&gt;Post Description&lt;/label&gt;
                                                    &lt;textarea id=&quot;description&quot; class=&quot;form-control&quot;  name=&quot;description&quot; &gt;&lt;/textarea&gt;
                                                &lt;/div&gt;
                                            &lt;/div&gt;
                                            &lt;button class=&quot;btn btn-primary&quot; type=&quot;submit&quot;&gt;Submit&lt;/button&gt;
                                        &lt;/form&gt;
                                    &lt;/div&gt;
                                &lt;/div&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;

@endsection


</pre>
<p>Open <strong>postedit.blade.php</strong> file and update the code your file:-</p>
<pre class="brush: php; title: ; notranslate">
@extends('layouts.app')

@section('content')
			
            &lt;div class=&quot;page-content&quot;&gt;
                    &lt;div class=&quot;container-fluid&quot;&gt;
                        &lt;div class=&quot;row&quot;&gt;
                            &lt;div class=&quot;col-lg-12&quot;&gt;
                                &lt;div class=&quot;portlet-box portlet-gutter ui-buttons-col mb-30&quot;&gt;
                                    
                                    &lt;div class=&quot;portlet-body&quot;&gt;
                                    	&lt;form class=&quot;needs-validation&quot; method=&quot;post&quot;  action=&quot;{{ url('postedit') }}/&lt;?php echo $posts&#x5B;0]-&gt;id; ?&gt;&quot; novalidate enctype=&quot;multipart/form-data&quot; &gt;
                                        &lt;input type = &quot;hidden&quot; name = &quot;_token&quot; value = &quot;&lt;?php echo csrf_token(); ?&gt;&quot;&gt;
                                            &lt;div class=&quot;form-row&quot;&gt;
                                                &lt;div class=&quot;col-md-12 mb-3&quot;&gt;
                                                    &lt;label for=&quot;validationCustom01&quot;&gt;Post Title&lt;/label&gt;
                                                    &lt;input type=&quot;text&quot; class=&quot;form-control&quot;  name=&quot;title&quot; placeholder=&quot;Page Title&quot; value = '&lt;?php echo $posts&#x5B;0]-&gt;title; ?&gt;' &gt;
                                                &lt;/div&gt;
                                                &lt;div class=&quot;col-md-12 mb-3&quot;&gt;
                                                    &lt;label for=&quot;image&quot;&gt;Post Description&lt;/label&gt;
                                                    &lt;textarea id=&quot;description&quot; class=&quot;form-control&quot;  name=&quot;description&quot; &gt;&lt;?php echo $posts&#x5B;0]-&gt;description; ?&gt;&lt;/textarea&gt;
                                                &lt;/div&gt;
                                            &lt;/div&gt;
                                            &lt;button class=&quot;btn btn-primary&quot; type=&quot;submit&quot;&gt;Submit&lt;/button&gt;
                                        &lt;/form&gt;
                                    &lt;/div&gt;
                                &lt;/div&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;



@endsection


</pre>
<h3>Step 5:- Add Routes in Web.php</h3>
<h5>Routes/web.php</h5>
<pre class="brush: php; title: ; notranslate">

Route::get('/post', 'PostController@index');
Route::get('/add-post', 'PostController@AddPost');
Route::post('/add-post','PostController@Store');
Route::get('/postedit/{id}', 'PostController@PostShow');
Route::post('/postedit/{slug}', 'PostController@Postedit');
Route::get('/postdelete/{id}', 'PostController@Delete');

</pre>
<h3>Step 6:- Run Laravel Vue CRUD App</h3>
<pre class="brush: php; title: ; notranslate">php artisan serve</pre>
<p>Open the URL in the browser:</p>
<pre class="brush: php; title: ; notranslate">http://127.0.0.1:8000</pre>
<p><img decoding="async" src="https://codeplaners.com/wp-content/uploads/2021/03/crud.jpg" alt="Laravel CRUD Operations"></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-framework-crud-operations/">Laravel Framework CRUD Operations</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/laravel-framework-crud-operations/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
