La ஒற்றைப் பக்க விண்ணப்பம் DB இல் அடிப்படை செயல்பாடுகளின் சுழற்சியை முடிக்க எங்களை அனுமதிக்கும்: உடன் உருவாக்கவும், படிக்கவும், புதுப்பிக்கவும் மற்றும் நீக்கவும் vue.js , Vue திசைவிகள் மற்றும் Laravel கட்டமைப்பு .
இப்போதெல்லாம், மிகவும் பிரபலமான JS கட்டமைப்புகள் Angular JS மற்றும் Vue JS ஆகும். கோண JS மற்றும் Vue JS மிகவும் பயனர் நட்பு மற்றும் மிகவும் பிரபலமான JS கட்டமைப்புகள். இது பக்கம் மற்றும் சக்திவாய்ந்த jQuery சரிபார்த்தல் இல்லாமல் முழு திட்டம் அல்லது பயன்பாடு மேலாண்மை வழங்குகிறது.
Vue Laravel உடன் முன்கூட்டியே தொகுக்கப்பட்டுள்ளது (இதனுடன் லாராவெல் கலவை , அடிப்படையிலான ஒரு சிறந்த படைப்பாக்க கருவி வெப்பேக் ) மற்றும் டெவலப்பர்கள் டிரான்ஸ்பைலர்கள், குறியீடு தொகுப்புகள், மூல வரைபடங்கள் அல்லது நவீன முகப்பு மேம்பாட்டின் பிற "அழுக்கு" அம்சங்களைப் பற்றி கவலைப்படாமல் சிக்கலான ஒற்றை பக்க பயன்பாடுகளை உருவாக்கத் தொடங்க அனுமதிக்கிறது.
PHP 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 இல், பாதைகள் மூலம் தேவைப்படும் போது மட்டுமே நீங்கள் கூறுகளை ஏற்ற முடியும்.
இப்போது நீங்கள் அனைத்து பாதைகள், vue-axios மற்றும் பிற சார்புகளை சேர்க்க வேண்டும்.
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
apri லோக்கல் ஹோஸ்ட்: 8000 உலாவியில்.
BlogInnovazione.it
முன்கணிப்பு பராமரிப்பு எண்ணெய் மற்றும் எரிவாயு துறையில் புரட்சியை ஏற்படுத்துகிறது, ஆலை மேலாண்மைக்கு ஒரு புதுமையான மற்றும் செயல்திறன் மிக்க அணுகுமுறையுடன்.…
செயற்கை நுண்ணறிவு சந்தையில் பிக் டெக்கின் நடத்தை குறித்து UK CMA எச்சரிக்கை விடுத்துள்ளது. அங்கு…
கட்டிடங்களின் ஆற்றல் திறனை மேம்படுத்த ஐரோப்பிய ஒன்றியத்தால் உருவாக்கப்பட்ட "கேஸ் கிரீன்" ஆணை, அதன் சட்டமன்ற செயல்முறையை முடித்தது...
இத்தாலியில் மின்வணிகம் தொடர்பான கசலேஜியோ அசோசியேட்டியின் ஆண்டு அறிக்கை வழங்கப்பட்டது. “AI-காமர்ஸ்: செயற்கை நுண்ணறிவுடன் கூடிய மின்வணிகத்தின் எல்லைகள்” என்ற தலைப்பில் அறிக்கை.