In this tutorial im going to share how to insert multiple value in one column in array. Follow this tutorial in this tutorial i’have to mentioned in very easy way.
First go to your Model and your fillable class.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
// use Illuminate\Database\Eloquent\Model;
use PHPUnit\Framework\Constraint\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class WebAcces extends Model
{
protected $fillable =[
'id',
'admin_id','admin_email','user_id','user_email','type_of_task','wizard_project_name','website',
'email_address','user_name','password','page_url','maintenance_engineer','slugname','slug_id','all_url'
];
protected $casts = ['all_url' => 'array'];
}
Next go to your controller and put below function
public function add_wizard_url(Request $request)
{
log::info('request me kya aa rha hai'.$request->project_name);
log::info('request me kya aa rha hai'.$request->facebook);
log::info('request me kya aa rha hai'.$request->twitter);
log::info('update function is working');
$input = [
'wizard_project_name' => $request->project_name,
'all_url' => [
'1' => $request->facebook,
'2' => $request->twitter,
]
];
$item = WebAcces::updateOrCreate(['wizard_project_name' => $request->project_name],$input);
$response = [
'success' => true,
'message' => 'Wizard Url Successfully.',
];
return response()->json($response, 200);
}
Now Data has been saved successfully.