找不到 Laravel 5 路由对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29741410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 Routing Object Not Found
提问by GandhyOnly
I ussualy using Laravel 4 and now Im trying to learn Laravel 5
我通常使用 Laravel 4,现在我正在尝试学习 Laravel 5
there's problem on Naming Controller Routes :
命名控制器路由存在问题:
i had route like :
我有这样的路线:
Route::get('/', [
'uses' => 'HomeController@viewHome',
'as' => 'home'
]);
Route::get('/events', [
'uses' => 'EventController@viewEvent',
'as' => 'event'
]);
when i run route as 'home' (localhost/laravel/) its work perfectly
当我以“home”(localhost/laravel/)的身份运行路由时,它的工作完美无缺
but when i run route as 'event' (localhost/laravel/events): Object not found!
但是当我将路由作为“事件”(localhost/laravel/events)运行时:找不到对象!
and i already make sure that viewEvent method running right by swap it like this:
我已经通过像这样交换它来确保 viewEvent 方法正确运行:
Route::get('/', [
'uses' => 'EventController@viewEvent',
'as' => 'home'
]);
Route::get('/events', [
'uses' => 'HomeController@viewHome',
'as' => 'event'
]);
i can run viewEvent but i cant run viewHome
我可以运行 viewEvent 但我不能运行 viewHome
any problem with my code?
我的代码有问题吗?
======================== SOLVED =============================
======================== 已解决 ======================== ====
with help @DamienPirzy and i realize when i disable /public/ folder i think i must make .htaccess out to main folder too :)
在@DamienPirzy 的帮助下,我意识到当我禁用 /public/ 文件夹时,我想我也必须将 .htaccess 放到主文件夹中:)
thanks all for fast response :) Problem Solved
感谢大家的快速响应:) 问题已解决
回答by kamlesh.bar
Put this htaccess into public folder. make sure you have apache mod rewrite working.
将此 htaccess 放入公用文件夹。确保你有 apache mod 重写工作。
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
回答by Kornkrit Leelhaphunt
i saw in routes.php
我在routes.php中看到
Route::get('/events', [
'uses' => 'EventController@viewEvent',
'as' => 'event'
]);
But u run
但是你跑
localhost/laravel/event
Should run
应该运行
localhost/laravel/events
回答by Tek Chansin
Could you check on .htaccess file? Cuz that screen error is from Apache. The request didn't go to Laravel App.
你能检查一下 .htaccess 文件吗?因为屏幕错误来自 Apache。该请求没有发送到 Laravel 应用程序。
or check mod_rewrite is enabled,or not?
或检查 mod_rewrite 是否启用?
回答by Rahul Tathod
try to change .htaccess file to this
尝试将 .htaccess 文件更改为此
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
回答by Vivek Sharma
Copy the htacess file from the public folder and paste it into the root directory. It should solve the problem, also check the spelling of all routes; they must be correct.
从 public 文件夹中复制 htacess 文件并将其粘贴到根目录中。它应该解决问题,还要检查所有路由的拼写;他们一定是正确的。