davy_yg's avatar
Level 27

Unable to upload file

Hello,

I am following this tutorial to upload file: http://laraveldaily.com/upload-multiple-files-laravel-5-4/

When I press the upload button: Object not found!

I wonder why?

0 likes
4 replies
shakti's avatar

can you show us your code as without that its quite difficult to answer your question

davy_yg's avatar
Level 27

upload_form.php

<form action="/upload" method="post" enctype="multipart/form-data">
     {{ csrf_field() }}
  Product name:
  <br />
 <input type="text" name="name" />
 <br /><br />
 Product photos (can attach more than one):
 <br />
 <input type="file" name="photos[]" multiple />
 <br /><br />
 <input type="submit" value="Upload" />
 </form>

UploadController.php

class UploadController extends Controller
{
//

public function uploadForm()
{
    return view('upload_form');
}

public function uploadSubmit(Request $request)
{
    $product = Product::create($request->all());
    foreach ($request->photos as $photo) {
        $filename = $photo->store('photos');
        ProductsPhoto::create([
            'product_id' => $product->id,
            'filename' => $filename
        ]);
    }
    return 'Upload successful!';
}
}

routes.php

 Route::get('/upload', 'UploadController@uploadForm');
 Route::post('/upload', 'UploadController@uploadSubmit');
phpMick's avatar

I would try dd($request->all()) in the first line of uploadSubmit to see what is getting posted.

Or debug in Chrome or Xdebug.

Mick

davy_yg's avatar
Level 27

The url turn into http://localhost/upload after pressing the upload button.

and:

Object not found!

public function uploadSubmit(Request $request)
{   
    dd($request->all());
    
    $product = Product::create($request->all());
    foreach ($request->photos as $photo) {
        $filename = $photo->store('photos');
        ProductsPhoto::create([
            'product_id' => $product->id,
            'filename' => $filename
        ]);
    }
    return 'Upload successful!';
}

Please or to participate in this conversation.