我在Laravel 5.2中有一个项目,一个问题是一条路线不起作用。当我打电话给这条路线时,它会转到Apache 404。
这些是我的一些路线:
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');
如您所见,这些是CRUD路线。我的应用程序中有更多这样的路由,但只有'/icons/{id}/edit'
给我错误。
我已经尝试更改路由以调用视图,但错误仍在继续。
Route::get ('/icons/{id}/edit', function () {
return view('welcome');
});
在我的开发者机器中,路由有效,但在生产服务器中则没有。
开发者机器:OSX + Apache + php7
生产服务器:Ubuntu 16 + Apache + php7
我该怎么做才能解决这些问题?如果您需要更多信息,请告诉我。谢谢。
修改:
IconController扩展了GeneralController。
在GeneralController中我有:
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,
]);
}
在IconController中我有:
protected function editData($id)
{
$record = Icon::findOrFail($id);
return (object)['record' => $record];
}
所有CRUD控制器都以相同的方式工作。
编辑2:
Apache日志。我访问了图标页面,然后是另一个CRUD(客户端)。
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"
答案 0 :(得分:2)
icons
是Apache中的标准别名。默认情况下,Laravel的.htaccess
已设置为Laravel仅处理对不存在的文件或目录的请求。看路线:
Route::get ('/icons', 'IconController@index');
Route::get ('/icons/create', 'IconController@create');
Route::post ('/icons', 'IconController@store');
就Apache而言,这些看起来都像是对文件的请求。这些文件不存在,因此Laravel处理请求,它们都能正常工作。
Route::get ('/icons/{id}/edit', 'IconController@edit');
在icons/
之后的尾部斜杠表示Apache认为它是一个目录,而Apache 知道一个名为icons的目录 - 它的标准图标别名。所以Laravel不会处理这个请求,而是留给Apache。但是没有名为" 44" (或者传递任何ID),在Apache的图标目录中,所以Apache抛出了404.
解决方案是删除Apache的icons
别名(假设您不需要它),as described for eg here,或为此路由使用其他名称,例如{{ 1}}等等。