<?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>Vue JS CRUD Archives - Codeplaners</title>
	<atom:link href="https://codeplaners.com/tag/vue-js-crud/feed/" rel="self" type="application/rss+xml" />
	<link>https://codeplaners.com/tag/vue-js-crud/</link>
	<description>Code Solution</description>
	<lastBuildDate>Fri, 12 Mar 2021 12:04:22 +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>Vue JS CRUD Archives - Codeplaners</title>
	<link>https://codeplaners.com/tag/vue-js-crud/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Build Laravel Vue JS CRUD Example</title>
		<link>https://codeplaners.com/how-to-build-laravel-vue-js-crud-example/</link>
					<comments>https://codeplaners.com/how-to-build-laravel-vue-js-crud-example/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 04 Mar 2021 09:13:56 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Vue JS CRUD]]></category>
		<category><![CDATA[vuejs]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=444</guid>

					<description><![CDATA[<p>This post was last updated on March 12th, 2021 at 12:04 pmHow to Build Laravel Vue JS CRUD Example, I will show you how to implement vue js crud example with Laravel. how to build a crude API in Laravel, for example Vue.Js Spa Crude in Laravel. In this laravel vue js crud example, you &#8230; <a href="https://codeplaners.com/how-to-build-laravel-vue-js-crud-example/" class="more-link">Continue reading<span class="screen-reader-text"> "How to Build Laravel Vue JS CRUD Example"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/how-to-build-laravel-vue-js-crud-example/">How to Build Laravel Vue JS CRUD Example</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p class="last-modified">This post was last updated on March 12th, 2021 at 12:04 pm</p><p>How to Build Laravel Vue JS CRUD Example,  I will show you how to implement vue js crud example with Laravel.</p>
<p>how to build a crude API in Laravel, for example Vue.Js Spa Crude in Laravel.</p>
<p>In this laravel vue js crud example, you will learn how to implement the laravel vue js crud (create, read, update and delete) spa with Vue js router and laravel.</p>
<h3>Laravel Vue JS CRUD (SPA) Example</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>Install NPM</li>
<li>Create Migration, Model and Controller</li>
<li>Add Routes In web.php</li>
<li>Add Vue Js Components</li>
<li>Add Vue Js Routes</li>
<li>Add Vue App.js</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=laravel@123
</pre>
<h3>Step 3:- Install NPM</h3>
<h4>Run the following command and install npm</h4>
<pre class="brush: php; title: ; notranslate">npm install</pre>
<h4>next step, use the command and install the vue-router and Vue-Axios will be used for calling Laravel API.</h4>
<pre class="brush: php; title: ; notranslate"> npm install vue-router vue-axios --save </pre>
<h4>Now after this we run this command</h4>
<pre class="brush: php; title: ; notranslate"> npm run watch </pre>
<p>npm run watch with this command compiles the assets.</p>
<h3>Step 4:- 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 Illuminate\Http\Request;
use App\Http\Resources\PostCollection;
use App\Post;
//codeplaners 
class PostController extends Controller
{
    // all posts
    public function index()
    {
        $posts = Post::all()-&gt;toArray();
        return array_reverse($posts);
    }
 
    // add post
    public function add(Request $request)
    {
        $post = new Post(&#x5B;
            'title' =&gt; $request-&gt;input('title'),
            'description' =&gt; $request-&gt;input('description')
        ]);
        $post-&gt;save();
 
        return response()-&gt;json('post successfully added');
    }
 
    // edit post
    public function edit($id)
    {
        $post = Post::find($id);
        return response()-&gt;json($post);
    }
 
    // update post
    public function update($id, Request $request)
    {
        $post = Post::find($id);
        $post-&gt;update($request-&gt;all());
 
        return response()-&gt;json('post successfully updated');
    }
 
    // delete post
    public function delete($id)
    {
        $post = Post::find($id);
        $post-&gt;delete();
 
        return response()-&gt;json('post successfully deleted');
    }
}

</pre>
<h3>Step 5:- Add Routes in Web.php</h3>
<h5>Routes/web.php</h5>
<pre class="brush: php; title: ; notranslate">
&lt;?php
 
Route::get('{any}', function () {
    return view('app');
})-&gt;where('any', '.*');
</pre>
<h5>Routes/Api.php</h5>
<pre class="brush: php; title: ; notranslate">
&lt;?php
use Illuminate\Http\Request;
 
 
Route::get('posts', 'PostController@index');
Route::group(&#x5B;'prefix' =&gt; 'post'], function () {
    Route::post('add', 'PostController@add');
    Route::get('edit/{id}', 'PostController@edit');
    Route::post('update/{id}', 'PostController@update');
    Route::delete('delete/{id}', 'PostController@delete');
});
</pre>
<h3>Step 6:- Add Vue Js</h3>
<p>To setup Vue js in Laravel, create one blade view file named <b>app.blade.php</b></p>
<p>update the code into your app.blade.php file as follow.<br />
<strong>resources/views/layout/app.blade.php </strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;!doctype html&gt;
&lt;html lang=&quot;{{ str_replace('_', '-', app()-&gt;getLocale()) }}&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
    &lt;meta name=&quot;csrf-token&quot; value=&quot;{{ csrf_token() }}&quot;/&gt;

    &lt;title&gt;Build Laravel Vue JS CRUD Example - CodePalners&lt;/title&gt;

    &lt;link href=&quot;{{ mix('css/app.css') }}&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot;/&gt;
    &lt;style&gt;
        .bg-light {
            background-color: #eae9e9 !important;
        }
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;app&quot;&gt;&lt;/div&gt;
&lt;script src=&quot;{{ mix('js/app.js') }}&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3>Step 7:- Add Vue Js Components</h3>
<p>Create Components folder this path <strong>resources/js/components</strong><br />
and components folder add file:</p>
<ul style="list-style: circle;padding: 0 0 0 16px;font-weight: 700;line-height: 26px;font-size: 16px;">
<li>App.vue</li>
<li>AllPost.vue</li>
<li>AddPost.vue</li>
<li>EditPost.vue</li>
</ul>
<p>Open <strong>App.vue</strong> file and update the code your file:-</p>
<pre class="brush: php; title: ; notranslate">
&lt;template&gt;
    &lt;div class=&quot;container&quot;&gt;
        &lt;div class=&quot;text-center&quot; style=&quot;margin: 20px 0px 20px 0px;&quot;&gt;
            &lt;span class=&quot;text-secondary&quot;&gt;Build Laravel Vue JS CRUD Example - CodePalners&lt;/span&gt;
        &lt;/div&gt;
 
        &lt;nav class=&quot;navbar navbar-expand-lg navbar-light bg-light&quot;&gt;
            &lt;div class=&quot;collapse navbar-collapse&quot;&gt;
                &lt;div class=&quot;navbar-nav&quot;&gt;
                    &lt;router-link to=&quot;/&quot; class=&quot;nav-item nav-link&quot;&gt;Home&lt;/router-link&gt;
                    &lt;router-link to=&quot;/add&quot; class=&quot;nav-item nav-link&quot;&gt;Add Post&lt;/router-link&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/nav&gt;
        &lt;br/&gt;
        &lt;router-view&gt;&lt;/router-view&gt;
    &lt;/div&gt;
&lt;/template&gt;
 
&lt;script&gt;
    export default {}
&lt;/script&gt;
</pre>
<p>Open <strong>AllPost.vue</strong> file and update the code your file:-</p>
<pre class="brush: php; title: ; notranslate">
&lt;template&gt;
    &lt;div&gt;
        &lt;h3 class=&quot;text-center&quot;&gt;All Posts&lt;/h3&gt;&lt;br/&gt;
 
        &lt;table class=&quot;table table-bordered&quot;&gt;
            &lt;thead&gt;
            &lt;tr&gt;
                &lt;th&gt;ID&lt;/th&gt;
                &lt;th&gt;Title&lt;/th&gt;
                &lt;th&gt;Description&lt;/th&gt;
                &lt;th&gt;Created At&lt;/th&gt;
                &lt;th&gt;Updated At&lt;/th&gt;
                &lt;th&gt;Actions&lt;/th&gt;
            &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
            &lt;tr v-for=&quot;post in posts&quot; :key=&quot;post.id&quot;&gt;
                &lt;td&gt;{{ post.id }}&lt;/td&gt;
                &lt;td&gt;{{ post.title }}&lt;/td&gt;
                &lt;td&gt;{{ post.description }}&lt;/td&gt;
                &lt;td&gt;{{ post.created_at }}&lt;/td&gt;
                &lt;td&gt;{{ post.updated_at }}&lt;/td&gt;
                &lt;td&gt;
                    &lt;div class=&quot;btn-group&quot; role=&quot;group&quot;&gt;
                        &lt;router-link :to=&quot;{name: 'edit', params: { id: post.id }}&quot; class=&quot;btn btn-primary&quot;&gt;Edit
                        &lt;/router-link&gt;
                        &lt;button class=&quot;btn btn-danger&quot; @click=&quot;deletePost(post.id)&quot;&gt;Delete&lt;/button&gt;
                    &lt;/div&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;/tbody&gt;
        &lt;/table&gt;
    &lt;/div&gt;
&lt;/template&gt;
 
&lt;script&gt;
    export default {
        data() {
            return {
                posts: &#x5B;]
            }
        },
        created() {
            this.axios
                .get('http://127.0.0.1:8000/api/posts')
                .then(response =&gt; {
                    this.posts = response.data;
                });
        },
        methods: {
            deletePost(id) {
                this.axios
                    .delete(`http://127.0.0.1:8000/api/post/delete/${id}`)
                    .then(response =&gt; {
                        let i = this.posts.map(item =&gt; item.id).indexOf(id); // find index of your object
                        this.posts.splice(i, 1)
                    });
            }
        }
    }
&lt;/script&gt;
</pre>
<p>Open <strong>AddPost.vue</strong> file and update the code your file:-</p>
<pre class="brush: php; title: ; notranslate">
&lt;template&gt;
    &lt;div&gt;
        &lt;h3 class=&quot;text-center&quot;&gt;Add Post&lt;/h3&gt;
        &lt;div class=&quot;row&quot;&gt;
            &lt;div class=&quot;col-md-6&quot;&gt;
                &lt;form @submit.prevent=&quot;addPost&quot;&gt;
                    &lt;div class=&quot;form-group&quot;&gt;
                        &lt;label&gt;Title&lt;/label&gt;
                        &lt;input type=&quot;text&quot; class=&quot;form-control&quot; v-model=&quot;post.title&quot;&gt;
                    &lt;/div&gt;
                    &lt;div class=&quot;form-group&quot;&gt;
                        &lt;label&gt;Description&lt;/label&gt;
                        &lt;input type=&quot;text&quot; class=&quot;form-control&quot; v-model=&quot;post.description&quot;&gt;
                    &lt;/div&gt;
                    &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Add Post&lt;/button&gt;
                &lt;/form&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/template&gt;
 
&lt;script&gt;
    export default {
        data() {
            return {
                post: {}
            }
        },
        methods: {
            addPost() {
 
                this.axios
                    .post('http://127.0.0.1:8000/api/post/add', this.post)
                    .then(response =&gt; (
                        this.$router.push({name: 'home'})
                        // console.log(response.data)
                    ))
                    .catch(error =&gt; console.log(error))
                    .finally(() =&gt; this.loading = false)
            }
        }
    }
&lt;/script&gt;
</pre>
<p>Open <strong>EditPost.vue</strong> file and update the code your file:-</p>
<pre class="brush: php; title: ; notranslate">
&lt;template&gt;
    &lt;div&gt;
        &lt;h3 class=&quot;text-center&quot;&gt;Edit Post&lt;/h3&gt;
        &lt;div class=&quot;row&quot;&gt;
            &lt;div class=&quot;col-md-6&quot;&gt;
                &lt;form @submit.prevent=&quot;updatePost&quot;&gt;
                    &lt;div class=&quot;form-group&quot;&gt;
                        &lt;label&gt;Title&lt;/label&gt;
                        &lt;input type=&quot;text&quot; class=&quot;form-control&quot; v-model=&quot;post.title&quot;&gt;
                    &lt;/div&gt;
                    &lt;div class=&quot;form-group&quot;&gt;
                        &lt;label&gt;Description&lt;/label&gt;
                        &lt;input type=&quot;text&quot; class=&quot;form-control&quot; v-model=&quot;post.description&quot;&gt;
                    &lt;/div&gt;
                    &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Update Post&lt;/button&gt;
                &lt;/form&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/template&gt;
 
&lt;script&gt;
    export default {
        data() {
            return {
                post: {}
            }
        },
        created() {
            this.axios
                .get(`http://127.0.0.1:8000/api/post/edit/${this.$route.params.id}`)
                .then((response) =&gt; {
                    this.post = response.data;
                    // console.log(response.data);
                });
        },
        methods: {
            updatePost() {
                this.axios
                    .post(`http://127.0.0.1:8000/api/post/update/${this.$route.params.id}`, this.post)
                    .then((response) =&gt; {
                        this.$router.push({name: 'home'});
                    });
            }
        }
    }
&lt;/script&gt;
</pre>
<h3>Step 8:- Add Vue Js Routes</h3>
<p>In this folder <strong>resources>js</strong> add <strong>routes.js</strong> file. </p>
<p>Open <strong>routes.js</strong> file and update the code your file:-</p>
<pre class="brush: plain; title: ; notranslate">
import AllPosts from './components/AllPost.vue';
import AddPost from './components/AddPost.vue';
import EditPost from './components/EditPost.vue';
 
export const routes = &#x5B;
    {
        name: 'home',
        path: '/',
        component: AllPosts
    },
    {
        name: 'add',
        path: '/add',
        component: AddPost
    },
    {
        name: 'edit',
        path: '/edit/:id',
        component: EditPost
    }
];
</pre>
<h3>Step 9:- Add Vue App.js</h3>
<p>this final step, please add the following code in the resources/js/app.js file:-</p>
<pre class="brush: php; title: ; notranslate">
require('./bootstrap');
import Vue from 'vue';
window.Vue = require('vue');
 
import App from './components/App.vue';
import VueRouter from 'vue-router';
import VueAxios from 'vue-axios';
import axios from 'axios';
import {routes} from './routes';
 
 
 
 
Vue.use(VueRouter);
Vue.use(VueAxios, axios);
 
const router = new VueRouter({
    mode: 'history',
    routes: routes
});
 
const app = new Vue({
    el: '#app',
    router: router,
    render: h =&gt; h(App),
});
</pre>
<h3>Step 9:- Run Laravel Vue CRUD App</h3>
<pre class="brush: php; title: ; notranslate">npm run watch</pre>
<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>The post <a rel="nofollow" href="https://codeplaners.com/how-to-build-laravel-vue-js-crud-example/">How to Build Laravel Vue JS CRUD Example</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/how-to-build-laravel-vue-js-crud-example/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
