Creating an advanced category with Laravel, Vue.js, and Inertia.js: Part 3 || লারাভেল ইনারসিয়া

Posted by

Advanced category create with Laravel, Vue.js, Inertia.js – Part 3

Advanced category create with Laravel, Vue.js, Inertia.js – Part 3

এই লেখা, সিরিজের তৃতীয় পর্বে আমরা লারাভেল, ভিউ.জেএস এবং ইনারসিয়া.জেএস ব্যবহার করে এডভান্সড ক্যাটাগরি তৈরি করা নিয়ে আলোচনা করব।

Step 1: Set up the database schema

First, let’s define the database schema for our advanced category creation. We will need to create a new table to store the categories, along with any additional fields that we want to include.


<?php
use IlluminateDatabaseMigrationsMigration;

class CreateCategoriesTable extends Migration
{
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->text('description')->nullable();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('categories');
}
}
?>

Step 2: Create the Category model and controller

Next, we need to create a model and controller for the categories. We can use the artisan command-line tool to generate the necessary files.


$ php artisan make:model Category
$ php artisan make:controller CategoryController

Step 3: Implement the category creation form

Now that we have the database schema and the necessary backend code in place, we can move on to creating the frontend form for adding new categories. We will use Vue.js and Inertia.js to handle the form submissions without having to perform full page refreshes.


<template>
<form @submit.prevent="createCategory">
<input type="text" v-model="name" />
<textarea v-model="description"></textarea>
<button type="submit">Create Category</button>
</form>
</template>
<script>
export default {
data() {
return {
name: '',
description: ''
}
},
methods: {
createCategory() {
this.$inertia.post('/categories', {
name: this.name,
description: this.description
});
}
}
}
</script>

Conclusion

In this article, we have discussed how to implement advanced category creation using Laravel, Vue.js, and Inertia.js. By following the steps outlined above, you should be able to create a fully functional category creation feature for your web application.