kdion4891 / laravel-livewire-forms

A dynamic, responsive Laravel Livewire form component with realtime validation, file uploads, array fields, and more.
243 stars 54 forks source link

File upload responds with required when the file is selected. #1

Closed WBDC closed 4 years ago

WBDC commented 4 years ago

Hi,

First, let me say thank you for this awesome package!

I was trying to help for a Livewire fellow (link) about file upload. initially I thought I still an manage this process by using the Image intervention package, but its not that simple.. I had a quick read on the Livewire articles and I came across your package.

I've followed your documentation, but seems like this doesn't work (at least for me) for file uploads.

lw_forms_img_upload

  1. When I select the file, the file name shows the file name on mouse hover, but it doesn't show in the input field
  2. The file doesn't reach the server as the img array is empty.

I've casted the image as an array.

Could you please advise?

Many thanks!

kdion4891 commented 4 years ago

Could be your storage setup. Right now it defaults to public. Check the network tab of chrome after you select a file - getting any errors from the response?

WBDC commented 4 years ago

Could be your storage setup. Right now it defaults to public. Check the network tab of chrome after you select a file - getting any errors from the response?

When I upload the file in the normal Controller it uploads the file just fine. Of course, for that, I use csrf token and post method. It uploads the file and puts it into the storage.

The $this->form_data shows that the img array is empty.

image

When I remove the dd($this->form_data) it throws an error

<!doctype html>
<html class="theme-light">
<!--
Symfony\Component\Routing\Exception\RouteNotFoundException: Route [imgs.create] not defined. in file C:\wamp64\www\wbdsupport\vendor\laravel\framework\src\Illuminate\Routing\UrlGenerator.php on line 420

#0 C:\wamp64\www\wbdsupport\vendor\laravel\framework\src\Illuminate\Routing\Redirector.php(176): Illuminate\Routing\UrlGenerator->route('imgs.create', Array)
#1 C:\wamp64\www\wbdsupport\app\Http\Livewire\ImgForm.php(27): Illuminate\Routing\Redirector->route('imgs.create')
#2 C:\wamp64\www\wbdsupport\vendor\kdion4891\laravel-livewire-forms\src\FormComponent.php(93): App\Http\Livewire\ImgForm->saveAndStayResponse()
#3 C:\wamp64\www\wbdsupport\vendor\livewire\livewire\src\ComponentConcerns\HandlesActions.php(88): Kdion4891\LaravelLivewireForms\FormComponent->saveAndStay()
#4 C:\wamp64\www\wbdsupport\vendor\livewire\livewire\src\Connection\ConnectionHandler.php(51): Livewire\Component->callMethod('saveAndStay', Array)
#5 C:\wamp64\www\wbdsupport\vendor\livewire\livewire\src\Connection\ConnectionHandler.php(21): Livewire\Connection\ConnectionHandler->processMessage('callMethod', Array, Object(App\Http\Livewire\ImgForm))
#6 C:\wamp64\www\wbdsupport\vendor\livewire\livewire\src\Connection\HttpConnectionHandler.php(11): Livewire\Connection\ConnectionHandler->handle(Array)
#7 C:\wamp64\www\wbdsupport\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(48): Livewire\Connection\HttpConnectionHandler->__invoke('img-form')

Is this any help for you?

Let me know what other information you need.

kdion4891 commented 4 years ago

It's because the imgs.create route that you're using in the saveAndStay() method doesn't exist.

WBDC commented 4 years ago

Hi Kevin,

I tried to check where it goes wrong without any success.

The route naming was my fault. Added it now, although seems like it doesn't like POST route, and it accepts a GET route. Here is all my stuff so hopefully you can see what's the problem.

Migration image

Model image

Route image

Component image

Again, I would expect some data to be shown when hits the imgs.create route, but the request()->all() returns an empty array.

kdion4891 commented 4 years ago

Is there anything in your laravel error log? Once a file is picked the component uploads it via axios through the package "upload-file" route, which actually just calls the component uploadFile function via AJAX.

kdion4891 commented 4 years ago

Closing for now until I hear a response.

kdion4891 commented 4 years ago

Make sure you added @stack('scripts') to your layout file where javascript goes.

ghost commented 4 years ago

I have this same issue, please advice

rpgwaiter commented 4 years ago

I am also having this same issue