This tutorial we will explain best way to insert comma seperated value in laravel.
Insert comma seperated value in laravel
If you want to save multiple images name in one row column by comma seperated then first is simply save many images by comma seperate and other is save in json object see in example.
User Controller
Here we upload multiple images of a user and save their name in json object form. first we save all images and get their name or assign in $image variable after that change array to json object or insert in db.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\User; class UserController extends Controller{ public function store(){ $name = 'anmol sharma'; $img1 = 'anmol.jpg'; $img2 = 'home.jpg'; $img3 = 'school.jpg'; $images = [$img1, $img2, $img3]; $images = json_encode($images); User::create(['name'=>$name, 'images'=>$images]); } }