dimanche 19 février 2017

Laravel same controller work with one route and not with another

I'm building my first application with laravel (version 5.4) but in the process of make a image upload with crop my route (originally photos) start getting a 404 error, after hours of debugging I get nothing, so changing the route and it started working, then blocked again, so I get a little confused and I think I'm really don't getting something here. my actual routes:

  Route::resource('partners', 'PartnersController');
  //Route::resource('pictures', 'PicturesController');
  Route::resource('blocktest', 'PicturesController');

this way everything works fine, my ajax post to my PicturesController and everything goes well, here is the controller function:

public function store(Request $request)
    {
        // echo 'hey';
        $requests = request()->file('picture');
        foreach ($requests as $picture) {
            $filename  = time() . '.' . $picture->getClientOriginalExtension();
            $path = public_path('pictures/' . $filename);
            Image::make($picture->getRealPath())->crop(600, 600)->save($path);


            $picture = new Picture;
            $picture->partner_id = $request['partner_id'];
            $picture->src = $filename;
            $picture->save();
        }
    }

but if I change the routes to:

Route::resource('partners', 'PartnersController');
Route::resource('pictures', 'PicturesController');
// Route::resource('blocktest', 'PicturesController')

trying to use the pictures and point the ajax to the new route I get a 404 from nginx.

Here's the result of a php artisan route:list

+--------+-----------+-------------------------+------------------+-----------------------------------------------------------+--------------+
| Domain | Method    | URI                     | Name             | Action                                                    | Middleware   |
+--------+-----------+-------------------------+------------------+-----------------------------------------------------------+--------------+
|        | GET|HEAD  | api/user                |                  | Closure                                                   | api,auth:api |
|        | GET|HEAD  | partners                | partners.index   | FrutoProibido\Http\Controllers\PartnersController@index   | web          |
|        | POST      | partners                | partners.store   | FrutoProibido\Http\Controllers\PartnersController@store   | web          |
|        | GET|HEAD  | partners/create         | partners.create  | FrutoProibido\Http\Controllers\PartnersController@create  | web          |
|        | GET|HEAD  | partners/{partner}      | partners.show    | FrutoProibido\Http\Controllers\PartnersController@show    | web          |
|        | PUT|PATCH | partners/{partner}      | partners.update  | FrutoProibido\Http\Controllers\PartnersController@update  | web          |
|        | DELETE    | partners/{partner}      | partners.destroy | FrutoProibido\Http\Controllers\PartnersController@destroy | web          |
|        | GET|HEAD  | partners/{partner}/edit | partners.edit    | FrutoProibido\Http\Controllers\PartnersController@edit    | web          |
|        | GET|HEAD  | pictures                | pictures.index   | FrutoProibido\Http\Controllers\PicturesController@index   | web          |
|        | POST      | pictures                | pictures.store   | FrutoProibido\Http\Controllers\PicturesController@store   | web          |
|        | GET|HEAD  | pictures/create         | pictures.create  | FrutoProibido\Http\Controllers\PicturesController@create  | web          |
|        | GET|HEAD  | pictures/{picture}      | pictures.show    | FrutoProibido\Http\Controllers\PicturesController@show    | web          |
|        | PUT|PATCH | pictures/{picture}      | pictures.update  | FrutoProibido\Http\Controllers\PicturesController@update  | web          |
|        | DELETE    | pictures/{picture}      | pictures.destroy | FrutoProibido\Http\Controllers\PicturesController@destroy | web          |
|        | GET|HEAD  | pictures/{picture}/edit | pictures.edit    | FrutoProibido\Http\Controllers\PicturesController@edit    | web          |
+--------+-----------+-------------------------+------------------+-----------------------------------------------------------+--------------+

I think it's a pretty strange behavior, but maybe I'm just not seeing something.

thanks!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kNZ93J
via IFTTT

Aucun commentaire:

Enregistrer un commentaire