【问题标题】:Route doesn't work for half paths - laravel路线不适用于半路径 - laravel
【发布时间】:2020-05-16 03:54:25
【问题描述】:

我在使用 Laravel 时遇到了问题。我的问题是我有连接到不同网页的路由,但是一半的网页没有加载,而另一个却有。我有每个页面的 PHP 页面并将它们连接起来。 我得到了 404 这是我的路线

Route::get('/', 'PagesController@index');
Route::get('/index', 'PagesController@index');
Route::get('/hub','PagesController@hub');
Route::get('/basicmod','PagesController@basicmod');
Route::get('/addquestion','PagesController@questions');
Route::get('/addquestion','PagesController@addquestion');
Route::get('/introtest','TestController@index');

所有路由都连接到页面控制器或测试控制器中的函数,例如:

public function addquestion(){
    $title = "Add Question";
    return view('pages.addquestion')->with('title',$title);
}

这里是我调用函数的地方:

<button onclick="window.location.href='http://localhost/microskills/public/hun/'"></button>
<button><a href="http://localhost/microskills/public/questions">Questions</a></button>

不是功能不起作用,也不是我在浏览器中输入localhost/skills/public/questions时按钮仍然不起作用

【问题讨论】:

  • 你在双重定义路线:Route::get('/addquestion','PagesController@questions'); Route::get('/addquestion','PagesController@addquestion'); 这是故意的吗?你可以有相同的签名,只要确保一个是post,另一个get ;)
  • 我把问题路由出去了,但它仍然不起作用?我希望他们都得到
  • 好吧,你可能希望它们都像 get 一样,但那是行不通的。一个get,一个post 或者更改签名。

标签: php html laravel routing


【解决方案1】:

哪些路线有效,哪些无效?

如果你正在运行 apache,你是否激活了 mod_rewrite?

运行此命令以激活 apache 中的 mod_rewrite:

sudo a2enmod rewrite

然后重启apache:

sudo systemctl restart apache2

【讨论】:

  • 我已经这样做了,但仍然无法正常工作。还有什么我需要安装的吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-29
  • 1970-01-01
  • 2019-10-13
  • 2011-07-12
  • 2015-12-24
  • 2014-06-04
  • 2017-04-20
相关资源
最近更新 更多