1

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?

3
  • Can you clarify you question a bit more? Why & what controller logic do you need to call from your view? View's shouldn't trigger controller logic. Your controllers should return a view and at the point the do that should be it for the controller. Commented Dec 2, 2016 at 17:50
  • its the same as everything. when you pass something to your view, well, you can include what you want into that view, and all the parameters will be available to that include file. Commented Dec 2, 2016 at 17:57
  • View1 displays userdata. Part of this userdata is an html label wich dispalys a count of orders that the user has made. This count should be displayed by another View2 (and @include), since I display this count more than once. But the problem is I don't know how to fill this second view with logic from the UserController concerning the amount of orders. If i would call this view via a route i could just let it run through a function wich returns a view but that doesn't work that way. Commented Dec 2, 2016 at 18:05

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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"; }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.