This context provides a tutorial on how to create a CRUD application with Laravel and Vue.js.
Abstract
The tutorial begins by explaining the basics of CRUD applications, Vue.js, and Laravel. It then provides a step-by-step guide on how to create a new Laravel 9 application, configure the database, install NPM, Vue, Vue-Router, and Vue-Axios, create a model, controller, and migration, define routes in web.php and api.php, create a Vue app, create components, define routes in Vue Router, include Vue.js dependencies to app.js, update webpack.mix.js, and run the development server. The tutorial also includes code snippets and screenshots for better understanding.
Bullet points
The tutorial explains how to create a new Laravel 9 application and configure the database.
It provides instructions on how to install NPM, Vue, Vue-Router, and Vue-Axios.
The tutorial guides on how to create a model, controller, and migration in Laravel.
It explains how to define routes in web.php and api.php.
The tutorial provides a step-by-step guide on how to create a Vue app and components.
It explains how to define routes in Vue Router and include Vue.js dependencies to app.js.
The tutorial guides on how to update webpack.mix.js and run the development server.
The tutorial includes code snippets and screenshots for better understanding.
Create CRUD Application with Laravel and Vue.js
Today, We are going to learn how to Create CRUD Application with Laravel and Vue.js. So, Vue.js is an open-source model–view–view model front end JavaScript framework for building user interfaces and single-page applications. It was created by Evan You, and is maintained by him and the rest of the active core team members.
CRUD apps are the user interface that we use to interact with databases through APIs. It is a specific type of application that supports the four basic operations: Create, read, update, delete. Broadly, CRUD apps consist of the database, the user interface, and the APIs.
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
*/publicfunctionedit(Category $category)
{
//
}
Now we define routes for our application open web.php and api.php from routes folder and update the following code:
web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------| 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('{any}', function () {
returnview('app');
})->where('any','.*');
api.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
useApp\Http\Controllers\CategoryController;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
So Now, we will create components for vue. Create new folder in resources/js and name it components. Now create the following files and folder in it:
App.vue
Welcome.vue
Category/List.vue
Category/Add.vue
Category/Edit.vue
Category is a folder inside components folder.
App.vue is the main file of our Vue app. We will define router-view in that file. All the routes will be shown in App.vue file.
Now, Update the following code to the following files:
Welcome.vue
<template><divclass="container mt-5"><divclass="col-12 text-center"><h1>LaravelTuts</h1><ahref="https://laraveltuts.com"target="_blank">Visit For More Tutorials</a></div></div></template>
Here we used lazy loading components. Vue JS handles loading components lazily with routes, so on the DOM, you can load components only when they are needed through routes.
Include Vue.js Dependencies to app.js
So Now, you need to add all routes, vue-axios, and other dependencies.
Update webpack.mix.js file in the root of the application.
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------| Mix Asset Management|--------------------------------------------------------------------------|| Mix provides a clean, fluent API for defining some Webpack build steps| for your Laravel applications. By default, we are compiling the CSS| file for the application as well as bundling up all the JS files.|
*/
So Today, We had learned how to Create CRUD Application with Laravel and Vue.js. Hope so this tutorial help you with your journey with learning Laravel. Please Note that we had use Vue 2 version for this tutorial. If you have any problem with this tutorial please comment you question below in the comment section so that we can solve you problems.