[英]href link is not working in laravel
i'm trying to build a hyperlink from index.blade.php to login.blade.php by route. 我试图通过路由建立从index.blade.php到login.blade.php的超链接。 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>
Set URL link in a menu link using Laravle blade template, use it {{url('dashboard')}}. 使用Laravle刀片模板在菜单链接中设置URL链接,并使用{{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. 我认为这将对您有所帮助。
Your error message points to a server problem, not Laravel. 您的错误消息指向服务器问题,而不是Laravel。
Make sure you'r mod_rewrite for apache is installed and enabled. 确保已安装并启用用于Apache的mod_rewrite。
a2enmod rewrite
service apache2 restart
Then check your Laravel with: 然后使用以下命令检查您的Laravel:
In your console, run: php artisan route:list
and see if you have a row similar to: 在您的控制台中,运行:
php artisan route:list
,看看是否有类似于以下内容的行:
| 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: 如果看不到
login
部分,请尝试使用以下方法清除路由的缓存:
php artisan route:clear
Other than that, you are doing everything properly. 除此之外,您所做的一切都正确。
I had the same problem (Ubuntu 18.04), it does not seem to be Laravel but Apache. 我遇到了同样的问题(Ubuntu 18.04),它似乎不是Laravel,而是Apache。
Workaround: Install Xampp and use it as Localhost. 解决办法:安装Xampp并将其用作Localhost。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.