A.HADDAD
A.HADDAD

Reputation: 1906

How to call a controller method from a link in a view in Laravel?

Blocked by the fact that OVH can't deploy .Net websites, we have turned to use Laravel (to use MVC).

so I have created a controller and I need to call it's methods from my layout, I tried this :

<a class="nav-link" href="{{action('HomeController@WhoWeAre')}}"><span style="text-decoration: underline;"><B>Acceuil</B></span></a>

where HomeContoller is my controller, and WhoWeAre is a method.

when I run my app, the website crash and I get this message :

ErrorException in UrlGenerator.php line 589: Action App\Http\Controllers\HomeController@WhoWeAre not defined. (View: C:\xampp\htdocs\laravel\resources\views\welcome.blade.php)

How can that be corrected, please?

Upvotes: 0

Views: 934

Answers (2)

A.HADDAD
A.HADDAD

Reputation: 1906

The Solution is just add a new route in web.php :

Route::get('/whoweare', 'HomeController@WhoWeAre');

Upvotes: 1

bluestar0505
bluestar0505

Reputation: 701

Please try following

  • Route
Route::get('/WhoWeAre', 'HomeController@WhoWeAre')->name('WhoWeAre');
  • View
<a class="nav-link" href="{{ route('WhoWeAre') }}"><span style="text-decoration: underline;"><B>Acceuil</B></span></a>

Upvotes: 0

Related Questions