Laravel Livewire – Multi select input data is lost after selection

  jquery-select2, laravel, laravel-livewire, php

i’m having a Clinic(id,name,&services from service class on it ) and when i need to store my services on database it saved normally but with an empty array without my services data
here is my view

<form class="form-horizontal" wire:submit.prevent="storeClinic">
    <div class="form-group">
        <label class="col-md-4 control-label">اسم العيادة</label>
            <div class="col-md-4">
                <input type="text" placeholder="اسم العيادة" id="name" name="name" class="form-control input-md" wire:model="name"/>
    <div class="form-group">
        <label class="col-md-4 control-label">اختارالخدمات</label><br/>
        <div class="col-md-4" wire:ignore>
            <select class="selectServices form-control input-md" id="selectServices" multiple wire:model.lazy="c_services">
                @foreach($services as $service)
                    <option value="{{$service->id}}">{{$service->name}}</option>
    <div class="form-group">
        <label class="col-md-4 control-label"></label>
        <div class="col-md-4">
            <button type="submit" class="btn btn-success">اضافة</button>

, my script

            var data = $('.selectServices').seleect2("val");
        window.livewire.on('clinicStore', () => {


, my component

public $name;
public $c_services = [];
use WithPagination;
public function storeClinic(){
    $input = [
        'name' => $this->name,
        'c_services' => json_encode($this->c_services),
    $this->name = '';
    $this->c_services = '';
    session()->flash('message','! تم اضافة العيادة بنجاح ');

and my model is

class Clinic extends Model

use HasFactory;

protected $table = "clinics";

protected $fillable = ['name','c_services'];

public function services(){
    return $this->belongsToMany(ServiceData::class,'serv_clinics');


i’m using livewire and select2 and needs to store my services data into clinics table c_services attribute is a longText item

Source: Laravel

Leave a Reply