Reputation: 53
I want to include a view like so: @include(user.myview)
, but within this view I need UserController logic. So I thought about calling a route: @include( route('user.route') )
which calls a Controllerfunction and returns the view but that isn't working. Any Ideas how to deal with this problem?
Upvotes: 1
Views: 255
Reputation: 5386
Simply add a link in you view and include it in your desired location. Link will have a route.
On clicking the link, controller method can be called. e.g. show_link.blade.php
In your show_link.blade.php view:
<a href= {{route('route-name')}} > Click here</a>
.
This route will call a method via .
Route::get('/call/method', 'controller@your_method_name')->name('route-name');
In controller, method your_method_name that will look like this:
public function your_method_name()
{
return "show what you want to";
}
Upvotes: 0
Reputation: 163748
You need to create view composer and use it to get the data.
View composers are callbacks or class methods that are called when a view is rendered. If you have data that you want to be bound to a view each time that view is rendered, a view composer can help you organize that logic into a single location.
Upvotes: 1