How to Store Multiple Select Values in Laravel? (ok)
https://www.itsolutionstuff.com/post/how-to-store-multiple-select-values-in-laravelexample.html
C:\xampp\htdocs\reset\database\migrations\2022_05_18_171017_create_posts_table.php
<?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->id();
$table->string('name');
$table->text('description');
$table->text('cat');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down() {
Schema::dropIfExists('posts');
}
}C:\xampp\htdocs\reset\app\Models\Post.php
C:\xampp\htdocs\reset\routes\web.php
C:\xampp\htdocs\reset\app\Http\Controllers\PostController.php
C:\xampp\htdocs\reset\resources\views\post.blade.php

How to Store Multiple Select Values in Laravel?
By Hardik Savani June 16, 2020 Category : LaravelPlayUnmuteLoaded: 1.15%Fullscreen
I am going to show you example of how to store multiple select values in laravel. i explained simply about how to store multiple select values in database using laravel. i explained simply about laravel store multiple select dropdown list values. we will help you to give example of how to save multiple select box value in laravel 6, laravel 7, laravel 8 and laravel 9.
Sometime we need to store multi select dropdown values in database using laravel. we can take json data type or text data type of that field so we can json_encode our array and store it into database.
Here, i will give you very simple and step by step example that will explain you how to store multiple select values in laravel using Accessors & Mutators. so let's see bellow example and bellow preview:
Preview:

Step 1: Create Migration
Here, in this example you need to create posts table with name, description and cat column. cat column has text or json data type. as bellow created:
database/migrations/2020_06_13_102114_create_posts_table.php
Now we can run migration using bellow command:
Step 2: Create Post Model
Here, we will create Post model with Accessors & Mutators, so when you store categories then it will make json_encode() and when you get then json_decode(). so let's see bellow code:
app/Post.php
Read Also: How to create middleware for XSS protection in Laravel?
Step 3: Create Routes
Here, we will simple create two routes one get route to access view and another post route for store data into database. so let's add two routes:
routes/web.php
Step 4: Create Controller
Here, we will simple create PostController with two method that assign with route. so let's add two routes:
app/Http/Controllers/PostController.php
Step 5: Create Blade File
In this step, we will create blade file post.blade.php file there we added form code with multi select dropdown box. so let's put bellow code:
resources/views/post.blade.php
Now we are ready to app.
You can run application using bellow command:
Read Also: Laravel Multi Select Dropdown with Checkbox Example
I hope it can help you...
Last updated
Was this helpful?