What seems to be the problem:
Cannot handle file upload without [Livewire\WithFileUploads] trait on the [projects-form] component class.
Steps to Reproduce:
i had an input set to files, but because photos will be stored on a different table, I decided to create a new Lw component
i moved whatever I had on the first Lw component to the newly created one
Are you using the latest version of Livewire:
yea
Do you have any screenshots or code examples:
no
ProjectForm (this one had some photos logic)
<?php
namespace App\Http\Livewire;
use App\Models\Project;
use Livewire\Component;
use Illuminate\Support\Facades\Auth;
class ProjectsForm extends Component
{
public Project $project;
public $title;
public $description;
public $display_date;
public $url;
protected $rules = [
'title' => 'required|min:6',
'description' => 'required|min:15',
'display_date' => 'required',
'url' => 'url|nullable'
];
public function submitForm()
{
$this->validate();
Project::create([
'user_id' => Auth::user()->id,
'title' => $this->title,
'description' => $this->description,
'display_date' => $this->display_date,
'url' => $this->url
]);
session()->flash('new_project', 'New project added, nice!');
return redirect()->to('/projects');
}
public function render()
{
return view('livewire.projects-form');
}
}
ProjectPhoto, this is now the new one from this component i should submit the photos
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithFileUploads;
use App\Models\ProjectPhoto;
class ProjectPhotos extends Component
{
use WithFileUploads;
public $photos = [];
public function submitPhotos()
{
$this->validate([
'photos.*' => 'image',
]);
foreach ($this->photos as $photo) {
$photo->store('projects/photos');
}
ProjectPhoto::create([
'project_id' => $this->project->id,
'photos.*' => $this->photos
]);
}
public function render()
{
return view('livewire.project-photos');
}
}