dongmei8511
2017-10-23 20:10
浏览 46
已采纳

href链接在laravel中不起作用

i'm trying to build a hyperlink from index.blade.php to login.blade.php by route. i defined a named route for this hyperlink but is not working.

here is my route code.

Route::get('/','HomeController@index');
Route::get('/login', 'HomeController@login_page')->name('login');

and here is my controller.

  public function login_page()
{
  return view('login');
}

and here is my view where i'm trying to set a hyperlink.

    <li><a href="{{route('login')}}">Log-in</a></li>

show this message

图片转代码服务由CSDN问答提供 功能建议

我正在尝试构建从 index.blade.php login.blade.php 路线。 我为这个超链接定义了一个命名路由但是没有工作。

这里是我的路由代码。

  Route :: get('  /','HomeController @ index'); 
Route :: get('/ login','HomeController @ login_page') - &gt; name('login'); 
   
 \  n 

这是我的控制器。

  public function login_page()
 {
 
 
 
返回视图('login'); 
} 
   
 
 

这是我的视图,我正在尝试设置超链接。

 &lt; li&gt;&lt; a href =  “{{route('login')}}”&gt;登录&lt; / a&gt;&lt; / li&gt; 
   
 
 

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongsuiying7773 2017-11-23 10:16
    已采纳

    Set URL link in a menu link using Laravle blade template, use it {{url('dashboard')}}. Use this link in the for example:

    <ul>
      <li>
        <a href="{{url('dashboard')}}" class="active">Dashboard</a>
      </li>
    </ul>
    

    I think it will be helpful for you.

    已采纳该答案
    打赏 评论
  • duanhua5523 2017-10-23 20:19

    Your error message points to a server problem, not Laravel.

    Make sure you'r mod_rewrite for apache is installed and enabled.

    a2enmod rewrite
    service apache2 restart
    

    Then check your Laravel with:

    In your console, run: php artisan route:list and see if you have a row similar to:

    | Domain | Method   | URI        | Name          | Action                                            | Middleware                  |
    +--------+----------+------------+---------------+---------------------------------------------------+-----------------------------+
    |        | GET|HEAD | login      | login         | App\Http\Controllers\HomeController@login_page    | web,guest                   |
    

    If you do not see the login part, try clearing route's cache with:

    php artisan route:clear
    

    Other than that, you are doing everything properly.

    打赏 评论
  • dqmfo84644 2018-07-29 16:41

    I had the same problem (Ubuntu 18.04), it does not seem to be Laravel but Apache.

    Workaround: Install Xampp and use it as Localhost.

    打赏 评论

相关推荐 更多相似问题