简体   繁体   中英

href link is not working in 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>

显示此讯息

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM