Ok so I am trying to get a livewire file upload to work. I expect to select the file and click the the upload button when it is then uploaded into storage. However as soon as i select the file it says File failed to upload and when i click the upload button it says upload field is required. Looking on the internet I found nothing that has worked (removing FILESYSTEM_DISK= from env and using FILESYSTEM_DISK=local) I removed file (replaced with upload) as thought maybe a reserved word. I also checked and changed permissions on storage/app/livewire-tmp - set to 777 still nothing - it does work with image uploads for profile though) whatever I try still it doesn't upload the file. My livewire files as follows:
<?php
namespace App\Http\Livewire;
use App\Models\Job;
use Livewire\Component;
use Livewire\WithFileUploads;
class UploadsTable extends Component
{
use WithFileUploads;
public Job $job;
public $upload;
protected $listeners =['refresh' => '$refresh'];
public function mount( Job $job )
{
$this->job = $job;
}
public function render()
{
return view('livewire.uploads-table');
}
public function uploadFile()
{
$this->validate([
'upload' => 'required|mimes:aac,ai,aiff,avi,bmp,c,cpp,csv,dat,dmg,doc,dotx,dwg,dxf,eps,exe,glv,gif,h,hpp,ics,iso,java,mp4,mid,mp4,txt,xlx,xls,pdf,jpg,png,php,css,html,js|max:2048'
]);
$this->upload->storeAs('uploads/' . $this->job_number, 'public' );
}
}
and the blade file
<div>
<form wire:submit.prevent="uploadFile" method="post">
@if ( count( $job->files() ) > 0 )
<table class="{{ getAppearances( 'table', 'class' ) }}">
<thead>
<th style="width:5%"> </th>
<th>File Name</th>
<th>Open</th>
</thead>
<tbody>
@foreach( $job->files() as $file )
<tr class="p-1 odd:bg-gray-200 even:bg-gray-50 odd:dark:bg-gray-700 even:dark:bg-gray-800">
<td><img src="{{ $file->extImg }}"/></td>
<td>{{ $file->name }}</td>
<td><a href="{{ $file->path }}" target="_blank"><i class="fa-solid fa-file-pen" aria-hidden="true"></i></a></td>
</tr>
@endforeach
</tbody>
</table>
@else
<p>No Uploads have been added for this job. You can add a file by clicking the button below this table.</p>
@endif
<br>
<input type="file" name="upload" wire:model="upload">
@error('upload') <span class="error">{{ $message }}</span> @enderror
<x-jet-button type="submit">
{{ __('Upload') }}
</x-jet-button>
</form>
</div>
The $job->files() function returns an array derived from files in the expected folder. It can be assumed to be an empty array
I have since created the sub-drirectory but no different as suspect it doesn't get this far and is failing creating the temp file. How do i check this? what should the permissions be (they are 777 right now)
*** EDIT ***
I was using a url via an apache.conf file. I ran php artisan serve and changed my .env APP_URL to use this and the message has stopped but how can i use the url I have configured with apache to work. My concern is when i put my changes onto a staging site this will stop working as it does on my local environment....
thanks