La ഒറ്റ പേജ് അപ്ലിക്കേഷൻ DB-യിലെ അടിസ്ഥാന പ്രവർത്തനങ്ങളുടെ ഒരു സൈക്കിൾ പൂർത്തിയാക്കാൻ ഞങ്ങളെ അനുവദിക്കും: ഇതുപയോഗിച്ച് സൃഷ്ടിക്കുക, വായിക്കുക, അപ്ഡേറ്റ് ചെയ്യുക, ഇല്ലാതാക്കുക Vue.js , Vue റൂട്ടറുകൾ ഒപ്പം ലാറവെൽ ഫ്രെയിംവർക്ക് .
ഇക്കാലത്ത്, ഏറ്റവും ജനപ്രിയമായ JS ചട്ടക്കൂടുകൾ Angular JS, Vue JS എന്നിവയാണ്. Angular JS ഉം Vue JS ഉം വളരെ ഉപയോക്തൃ-സൗഹൃദവും ഏറ്റവും ജനപ്രിയവുമായ JS ചട്ടക്കൂടുകളാണ്. പേജ് പുതുക്കാതെയും ശക്തമായ jquery മൂല്യനിർണ്ണയവും കൂടാതെ മുഴുവൻ പ്രോജക്റ്റിന്റെയും അല്ലെങ്കിൽ ആപ്ലിക്കേഷന്റെയും മാനേജ്മെന്റ് ഇത് നൽകുന്നു.
വ്യൂ ലാറവെൽ (കൂടാതെ ലാറവെൽ മിക്സ് , അടിസ്ഥാനമാക്കിയുള്ള ഒരു മികച്ച രചനാ ഉപകരണം വെബ്പായ്ക്ക് ) കൂടാതെ ട്രാൻസ്പൈലറുകൾ, കോഡ് പാക്കേജുകൾ, സോഴ്സ് മാപ്പുകൾ അല്ലെങ്കിൽ ആധുനിക ഫ്രണ്ട്എൻഡ് വികസനത്തിന്റെ മറ്റ് "വൃത്തികെട്ട" വശങ്ങൾ എന്നിവയെക്കുറിച്ച് ആകുലപ്പെടാതെ സങ്കീർണ്ണമായ സിംഗിൾ പേജ് ആപ്ലിക്കേഷനുകൾ നിർമ്മിക്കാൻ ഡവലപ്പർമാരെ അനുവദിക്കുന്നു.
പിഎച്ച്പി 7.4
ലാരാവെൽ 8.x
MySQL
ആദ്യം, ടെർമിനൽ തുറന്ന് ഒരു പുതിയ ലാറവൽ പ്രോജക്റ്റ് സൃഷ്ടിക്കുന്നതിന് ഇനിപ്പറയുന്ന കമാൻഡ് പ്രവർത്തിപ്പിക്കുക:
composer create-project --prefer-dist laravel/laravel crud-spa
അല്ലെങ്കിൽ, നിങ്ങൾ ഒരു കമ്പോസർ ഗ്ലോബൽ ഡിപൻഡൻസിയായി Laravel Installer ഇൻസ്റ്റാൾ ചെയ്താൽ:
laravel new crud-spa
ഇൻസ്റ്റാളേഷന് ശേഷം നിങ്ങളുടെ പ്രോജക്റ്റ് റൂട്ട് ഡയറക്ടറിയിലേക്ക് പോകുക, .env ഫയൽ തുറന്ന് ഡാറ്റാബേസ് വിശദാംശങ്ങൾ ഇനിപ്പറയുന്ന രീതിയിൽ സജ്ജമാക്കുക:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=<DATABASE NAME>
DB_USERNAME=<DATABASE USERNAME>
DB_PASSWORD=<DATABASE PASSWORD>
ഫ്രണ്ട്-എൻഡ് ഡിപൻഡൻസികൾ ഇൻസ്റ്റാൾ ചെയ്യാൻ ഇനിപ്പറയുന്ന കമാൻഡ് പ്രവർത്തിപ്പിക്കുക:
npm install
അതിനുശേഷം, ഇൻസ്റ്റാൾ ചെയ്യുക കാഴ്ച , വ്യൂ-റൂട്ടർ e വ്യൂ-ആക്സിയോസ് . Laravel ബാക്കെൻഡ് API-യെ വിളിക്കാൻ Vue-axios ഉപയോഗിക്കും. ടെർമിനലിൽ ഇനിപ്പറയുന്ന കമാൻഡ് പ്രവർത്തിപ്പിക്കുക:
npm install vue vue-router vue-axios --save
ഒരു വിഭാഗ ടെംപ്ലേറ്റ്, മൈഗ്രേഷൻ, കൺട്രോളർ എന്നിവ സൃഷ്ടിക്കുക. അതിനായി താഴെ പറയുന്ന കമാൻഡ് പ്രവർത്തിപ്പിക്കുക:
php artisan make:model Category -mcr
-എംസിആർ ഈ വിഷയം സിംഗിൾ കമാൻഡ് സിന്തസിസ് ഉപയോഗിച്ച് മോഡൽ, മൈഗ്രേഷൻ, കൺട്രോളർ എന്നിവ സൃഷ്ടിക്കും.
ഇപ്പോൾ, നിന്ന് കാറ്റഗറി മൈഗ്രേഷൻ ഫയൽ തുറക്കുക ഡാറ്റാബേസുകൾ / മൈഗ്രേഷൻ കൂടാതെ ഫംഗ്ഷനിലേക്ക് കോഡ് മാറ്റിസ്ഥാപിക്കുക മുകളിലേക്ക് () :
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title');
$table->text('description');
$table->timestamps();
});
}
ഇനിപ്പറയുന്ന കമാൻഡ് ഉപയോഗിച്ച് ഡാറ്റാബേസ് മൈഗ്രേറ്റ് ചെയ്യുക:
php artisan migrate
ഇപ്പോൾ, Category.php ടെംപ്ലേറ്റ് തുറക്കുകapp/Models
കൂടാതെ ഫയലിലെ കോഡ് എഡിറ്റ് ചെയ്യുക model
Category.php:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Category extends Model {
use HasFactory;
protected $fillable = ['title','description'];
}
?>
അതിനുശേഷം, തുറക്കുക CategoryController.php സൂചികയിൽ കോഡ് ചേർക്കുക, സംഭരിക്കുക, അപ്ഡേറ്റ് ചെയ്യുക, ഇല്ലാതാക്കുക രീതികൾ ഇനിപ്പറയുന്ന രീതിയിൽ ചെയ്യുക:
<?php
namespace App\Http\Controllers;
use App\Models\Category;
use Illuminate\Http\Request;
class CategoryController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$categories = Category::all(['id','title','description']);
return response()->json($categories);
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$category = Category::create($request->post());
return response()->json([
'message'=>'Category Created Successfully!!',
'category'=>$category
]);
}
/**
* Display the specified resource.
*
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
*/
public function show(Category $category)
{
return response()->json($category);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Category $category)
{
$category->fill($request->post())->save();
return response()->json([
'message'=>'Category Updated Successfully!!',
'category'=>$category
]);
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
*/
public function destroy(Category $category)
{
$category->delete();
return response()->json([
'message'=>'Category Deleted Successfully!!'
]);
}
}
അല്ല defiഅവ പൂർത്തിയാക്കുക routes
ഫയലുകളിൽ web.php e api.php . ഫോൾഡറിലേക്ക് പോകുക routes
കൂടാതെ web.php, api.php ഫയൽ തുറന്ന് ഇനിപ്പറയുന്നവ അപ്ഡേറ്റ് ചെയ്യുക routes
:
routes/web.php
<?php
Route::get('{any}', function () {
return view('app');
})->where('any', '.*');
routes/api.php
<?php
Route::resource('category',App\Http\Controllers\CategoryController::class)->only(['index','store','show','update','destroy']);
ഈ ഘട്ടത്തിൽ, ഡയറക്ടറിയിലേക്ക് പോകുക ഉറവിടം/കാഴ്ചകൾ, ഫയൽ സൃഷ്ടിക്കുക app.blade.php എന്നതിലേക്ക് ഇനിപ്പറയുന്ന കോഡ് ചേർക്കുക app.blade.php:
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" value="{{ csrf_token() }}"/>
<title>Laravel Vue CRUD App</title>
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet" type="text/css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<link href="{{ mix('css/app.css') }}" type="text/css" rel="stylesheet"/>
</head>
<body>
<div id="app">
</div>
<script src="{{ mix('js/app.js') }}" type="text/javascript"></script>
</body>
</html>
ഈ ഘട്ടത്തിൽ, ഫോൾഡറിലേക്ക് പോകുക resource/js
, ഫോൾഡർ സൃഷ്ടിക്കുക components
കൂടാതെ ഇനിപ്പറയുന്ന രീതിയിൽ ഫയലുകൾ സൃഷ്ടിക്കുക:
View app
Welcome.vue
Category/List.vue
Category/Add.vue
Category/Edit.vue
അപ്ലിക്കേഷൻ വ്യൂ ഞങ്ങളുടെ Vue ആപ്പിന്റെ പ്രധാന ഫയലാണിത്. Defiഞങ്ങൾ പൂർത്തിയാക്കും റൂട്ടർ കാഴ്ച ആ ഫയലിൽ. എല്ലാ പാതകളും ഫയലിൽ ദൃശ്യമാകും അപ്ലിക്കേഷൻ വ്യൂ .
ഫയൽ തുറക്കുക Welcome.vue
ആ ഫയലിൽ ഇനിപ്പറയുന്ന കോഡ് അപ്ഡേറ്റ് ചെയ്യുക:
<template>
<div class="container mt-5">
<div class="col-12 text-center">
<h1>Laravel Vuejs CRUD</h1>
</div>
</div>
</template>
App.vue ഫയൽ തുറന്ന് കോഡ് ഇനിപ്പറയുന്ന രീതിയിൽ അപ്ഡേറ്റ് ചെയ്യുക:
<template>
<main>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<router-link to="/" class="navbar-brand" href="#">Laravel Vue Crud App</router-link>
<div class="collapse navbar-collapse">
<div class="navbar-nav">
<router-link exact-active-class="active" to="/" class="nav-item nav-link">Home</router-link>
<router-link exact-active-class="active" to="/category" class="nav-item nav-link">Category</router-link>
</div>
</div>
</div>
</nav>
<div class="container mt-5">
<router-view></router-view>
</div>
</main>
</template>
<script>
export default {}
</script>
പിന്നെ, തുറക്കുക resource / js / components / category / List.vue
ഫയലിൽ ഇനിപ്പറയുന്ന കോഡ് ചേർക്കുക:
<template>
<div class="row">
<div class="col-12 mb-2 text-end">
<router-link :to='{name:"categoryAdd"}' class="btn btn-primary">Create</router-link>
</div>
<div class="col-12">
<div class="card">
<div class="card-header">
<h4>Category</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>Description</th>
<th>Actions</th>
</tr>
</thead>
<tbody v-if="categories.length > 0">
<tr v-for="(category,key) in categories" :key="key">
<td>{{ category.id }}</td>
<td>{{ category.title }}</td>
<td>{{ category.description }}</td>
<td>
<router-link :to='{name:"categoryEdit",params:{id:category.id}}' class="btn btn-success">Edit</router-link>
<button type="button" @click="deleteCategory(category.id)" class="btn btn-danger">Delete</button>
</td>
</tr>
</tbody>
<tbody v-else>
<tr>
<td colspan="4" align="center">No Categories Found.</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name:"categories",
data(){
return {
categories:[]
}
},
mounted(){
this.getCategories()
},
methods:{
async getCategories(){
await this.axios.get('/api/category').then(response=>{
this.categories = response.data
}).catch(error=>{
console.log(error)
this.categories = []
})
},
deleteCategory(id){
if(confirm("Are you sure to delete this category ?")){
this.axios.delete(`/api/category/${id}`).then(response=>{
this.getCategories()
}).catch(error=>{
console.log(error)
})
}
}
}
}
</script>
അതിനുശേഷം, തുറക്കുക resource /js/components/category/Add.vue
ഫയലിൽ ഇനിപ്പറയുന്ന കോഡ് അപ്ഡേറ്റ് ചെയ്യുക:
<template>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4>Add Category</h4>
</div>
<div class="card-body">
<form @submit.prevent="create">
<div class="row">
<div class="col-12 mb-2">
<div class="form-group">
<label>Title</label>
<input type="text" class="form-control" v-model="category.title">
</div>
</div>
<div class="col-12 mb-2">
<div class="form-group">
<label>Description</label>
<input type="text" class="form-control" v-model="category.description">
</div>
</div>
<div class="col-12">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name:"add-category",
data(){
return {
category:{
title:"",
description:""
}
}
},
methods:{
async create(){
await this.axios.post('/api/category',this.category).then(response=>{
this.$router.push({name:"categoryList"})
}).catch(error=>{
console.log(error)
})
}
}
}
</script>
അതിനുശേഷം, തുറക്കുക resource /js/components/category/Edit.vue
ഫയലിൽ ഇനിപ്പറയുന്ന കോഡ് അപ്ഡേറ്റ് ചെയ്യുക:
<template>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4>Update Category</h4>
</div>
<div class="card-body">
<form @submit.prevent="update">
<div class="row">
<div class="col-12 mb-2">
<div class="form-group">
<label>Title</label>
<input type="text" class="form-control" v-model="category.title">
</div>
</div>
<div class="col-12 mb-2">
<div class="form-group">
<label>Description</label>
<input type="text" class="form-control" v-model="category.description">
</div>
</div>
<div class="col-12">
<button type="submit" class="btn btn-primary">Update</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name:"update-category",
data(){
return {
category:{
title:"",
description:"",
_method:"patch"
}
}
},
mounted(){
this.showCategory()
},
methods:{
async showCategory(){
await this.axios.get(`/api/category/${this.$route.params.id}`).then(response=>{
const { title, description } = response.data
this.category.title = title
this.category.description = description
}).catch(error=>{
console.log(error)
})
},
async update(){
await this.axios.post(`/api/category/${this.$route.params.id}`,this.category).then(response=>{
this.$router.push({name:"categoryList"})
}).catch(error=>{
console.log(error)
})
}
}
}
</script>
ഇപ്പോൾ, നിങ്ങൾ ചെയ്യണം defiപൂർത്തിയാക്കുക Vue routes
, ഇത് ചെയ്യുന്നതിന് ഫോൾഡറിലേക്ക് പോകുക resource / js
, ഫയൽ സൃഷ്ടിക്കുക route.js
ഫയലിൽ ഇനിപ്പറയുന്ന കോഡ് അപ്ഡേറ്റ് ചെയ്യുക:
const Welcome = () => import('./components/Welcome.vue' /* webpackChunkName: "resource/js/components/welcome" */)
const CategoryList = () => import('./components/category/List.vue' /* webpackChunkName: "resource/js/components/category/list" */)
const CategoryCreate = () => import('./components/category/Add.vue' /* webpackChunkName: "resource/js/components/category/add" */)
const CategoryEdit = () => import('./components/category/Edit.vue' /* webpackChunkName: "resource/js/components/category/edit" */)
export const routes = [
{
name: 'home',
path: '/',
component: Welcome
},
{
name: 'categoryList',
path: '/category',
component: CategoryList
},
{
name: 'categoryEdit',
path: '/category/:id/edit',
component: CategoryEdit
},
{
name: 'categoryAdd',
path: '/category/add',
component: CategoryCreate
}
]
ഇവിടെ ഞങ്ങൾ ഘടകങ്ങൾ ഉപയോഗിച്ചു മന്ദഗതിയിലുള്ള ലോഡിംഗ്. വ്യൂ ജെ.എസ് ഒരു വിധത്തിൽ ഘടകങ്ങളുടെ ലോഡിംഗ് നിയന്ത്രിക്കുന്നു lazy
പാതകൾ ഉപയോഗിച്ച്, അതിനാൽ DOM-ൽ നിങ്ങൾക്ക് പാത്തുകളിലൂടെ ആവശ്യമുള്ളപ്പോൾ മാത്രം ഘടകങ്ങൾ ലോഡ് ചെയ്യാൻ കഴിയും.
ഇപ്പോൾ നിങ്ങൾ എല്ലാ പാതകളും വ്യൂ-ആക്സിയോകളും മറ്റ് ഡിപൻഡൻസികളും ചേർക്കേണ്ടതുണ്ട്.
resource / js / app.js
require('./bootstrap');
import vue from 'vue'
window.Vue = 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 => h(App),
});
webpack.mix.js
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.
|
*/
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
//
]).vue();
ടെർമിനൽ തുറന്ന് ഈ കമാൻഡ് പ്രവർത്തിപ്പിക്കുക:
npm run watch
php artisan serve
ഏപ്രിൽ ലോക്കൽഹോസ്റ്റ്: 8000 ബ്രൗസറിൽ.
BlogInnovazione.it
ആപ്പിൾ വിഷൻ പ്രോ കൊമേഴ്സ്യൽ വ്യൂവർ ഉപയോഗിച്ചുള്ള ഒഫ്താൽമോപ്ലാസ്റ്റി ഓപ്പറേഷൻ കാറ്റാനിയ പോളിക്ലിനിക്കിൽ നടത്തി.
കളറിംഗ് വഴി മികച്ച മോട്ടോർ കഴിവുകൾ വികസിപ്പിക്കുന്നത് എഴുത്ത് പോലെയുള്ള കൂടുതൽ സങ്കീർണ്ണമായ കഴിവുകൾക്ക് കുട്ടികളെ സജ്ജമാക്കുന്നു. നിറം കൊടുക്കാൻ...
നാവിക മേഖല ഒരു യഥാർത്ഥ ആഗോള സാമ്പത്തിക ശക്തിയാണ്, അത് 150 ബില്യൺ വിപണിയിലേക്ക് നാവിഗേറ്റ് ചെയ്തു...
കഴിഞ്ഞ തിങ്കളാഴ്ച, ഫിനാൻഷ്യൽ ടൈംസ് ഓപ്പൺഎഐയുമായി ഒരു കരാർ പ്രഖ്യാപിച്ചു. FT അതിൻ്റെ ലോകോത്തര പത്രപ്രവർത്തനത്തിന് ലൈസൻസ് നൽകുന്നു…