$this->skills is an array
'skill_id' => $this->skills,
You set it here in mount()
$this->skills = collect($this->skill)->map(function($value) use ($data) {
$data[$value->skill_id] = '';
return $data;
})->toArray();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
hello guys am trying to submit a form to my database and am getting this error ErrorException Array to string conversion
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="bmd-label-floating">Class Name/label>
<input type="text" wire:model="title" class="form-control @error('title') is-invalid @enderror" placeholder="EX: 1st grade">
@error('title')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
</div>
<div class="current-step">
<!-- filepond -->
<div class="row">
<div class="col-md-12">
<div
wire:ignore
x-data
x-init="
FilePond.registerPlugin(FilePondPluginImagePreview);
FilePond.setOptions({
AllowMultiple: 'multiple' ? 'true' : 'false',
server: {
process: (fieldName, file, metadata, load, error, progress, abort, transfer, options) => {
@this.upload('uploadedFiles', file, load, error, progress)
},
revert: (filename, load) => {
@this.removeUpload('uploadedFiles', filename, load)
},
},
});
FilePond.create($refs.input);
"
>
<label>File Upload</label>
<input type="file" x-ref="input" wire:model="uploadedFiles" multiple>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="bmd-label-floating">Skills required for your project?</label>
<div wire:ignore class="bootstrap-tagsinput info-badge">
<select wire:model="skills" class="form-control js-select2-multi" data-placeholder="Enter Skills here..." multiple>
@foreach($skill as $item)
<option value="{{ $item->id }}">{{ $item->name }}</option>
@endforeach
</select>
</div>
</div>
</div>
</div>
</div>
my livewire controller
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithFileUploads;
use App\Models\Skills;
use App\Models\Post;
use Illuminate\Support\Facades\Auth;
class Post extends Component
{
use WithFileUploads;
public $title;
public $uploadedFiles;
public $skill = '';
protected function rules ()
{
return [
'title' => 'required|min:3',
'uploadedFiles' => 'required|file|mimes:png,jpg,pdf|max:5120',
'skills' => 'required',
];
}
public function mount()
{
$this->skill = Skills::all();
$data = [];
$this->skills = collect($this->skill)->map(function($value) use ($data) {
$data[$value->skill_id] = '';
return $data;
})->toArray();
}
public function updated($field)
{
$this->validateOnly($field);
}
public function Post ()
{
$this->validate();
$path = $this->uploadedFiles->store('public/storage/Posted');
Post::create([
'title' => $this->title,
'uploadedFiles' => $path,
'skill_id' => $this->skills,
'user_id' => Auth::user()->id
]);
$this->reset();
return redirect()->back()->with('success', 'posted Successful');
}
}
I even tried to remove this return redirect()->back()->with('success', 'posted Successful'); without it as am used to submit a form but getting that error
Please or to participate in this conversation.