0

I have a project in Laravel 5.2 and a problem that one route not work. When I call this route it goes to Apache 404.

These are some of my routes:

Route::get      ('/icons',                 'IconController@index');
Route::get      ('/icons/create',          'IconController@create');
Route::post     ('/icons',                 'IconController@store');
Route::get      ('/icons/{id}/edit',       'IconController@edit');
Route::patch    ('/icons/{id}',            'IconController@update');
Route::delete   ('/icons',                 'IconController@destroy');

As you can see, these are CRUD routes. I have many more routes like these in my application but just '/icons/{id}/edit' give me the error.

I already tried change the route to call a view, but the error continues.

Route::get      ('/icons/{id}/edit',       function () {
    return view('welcome');
});

In my developer machine the route works, but in the production server don't.

Developer machine: OSX + Apache + php7

Production server: Ubuntu 16 + Apache + php7

What should I do to fix these? If you need more information please tell me. Thanks.

EDIT:

IconController extends GeneralController.

In GeneralController I have:

public function edit($id, Request $request)
{
    $log = new ActivityLogRepository();
    $log->store($request, 'R');

    $this->request = $request;
    $segments = $request->segments();

    return view($this->viewDir.'.form', [
        'data' => $this->editData($id),
        'name' => $this->name,
        'icon' => $this->icon,
        'nameAction' => trans('messages.button_'.end($segments)),
        'baseRoute' => $this->baseRoute,
        'viewDir' => $this->viewDir,
    ]);
}

In IconController I have:

protected function editData($id)
{
    $record = Icon::findOrFail($id);

    return (object)['record' => $record];
}

All CRUD controllers work the same way.

EDIT 2:

Apache log. I accessed the icons page and then another CRUD (clients).

my_ip - - [01/Sep/2017:13:21:40 +0000] "GET / HTTP/1.1" 302 1377 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
my_ip - - [01/Sep/2017:13:21:40 +0000] "GET /login HTTP/1.1" 200 2881 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
my_ip - - [01/Sep/2017:13:21:55 +0000] "POST /login HTTP/1.1" 302 1347 "http://example.com/login" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
my_ip - - [01/Sep/2017:13:21:55 +0000] "GET / HTTP/1.1" 200 11140 "http://example.com/login" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
my_ip - - [01/Sep/2017:13:21:56 +0000] "GET /images/users/thumbs/5968097a83fae.png HTTP/1.1" 304 181 "http://example.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
my_ip - - [01/Sep/2017:13:21:57 +0000] "GET /events/notification HTTP/1.1" 200 972 "http://example.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
my_ip - - [01/Sep/2017:13:22:04 +0000] "GET /icons HTTP/1.1" 200 7285 "http://example.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
my_ip - - [01/Sep/2017:13:22:11 +0000] "GET /icons/44/edit HTTP/1.1" 404 510 "http://example.com/icons" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
my_ip - - [01/Sep/2017:13:29:18 +0000] "GET /clients HTTP/1.1" 200 6523 "http://example.com/icons" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
my_ip - - [01/Sep/2017:13:29:20 +0000] "GET /clients/16/edit HTTP/1.1" 200 12344 "http://example.com/clients" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"

1 Answers1

2

icons is a standard alias in Apache. Laravel's .htaccess by default is set up so that Laravel will only handle requests for files or directories which do not exist. Looking at the routes:

Route::get      ('/icons',                 'IconController@index');
Route::get      ('/icons/create',          'IconController@create');
Route::post     ('/icons',                 'IconController@store');

These all look like requests to files, as far as Apache is concerned. Those files don't exist, so Laravel handles the requests, and they all work fine.

Route::get      ('/icons/{id}/edit',       'IconController@edit');

Trailing slash after on icons/ here means Apache thinks it is a directory, and Apache does know about a directory called icons - its standard icons alias. So Laravel does not handle this request, and it is left for Apache. But there is no such directory called "44" (or whatever ID is passed), in Apache's icons dir, so Apache throws a 404.

The solution is to either remove Apache's icons alias (assuming you don't need it), as described for eg here, or use a different name for this route, like my-icons etc.

Don't Panic
  • 13,965
  • 5
  • 32
  • 51