1

I have a table which consists of user data. I have created a view in which I am able to view the user's name and on clicking on the name I am expecting to view the detailed info of that particular user. Could you please guide me through the issue? It would be a great help!

5 Answers 5

3

If you want to share a variable between more than one view, you can easily use the share method on the facade. There is actually a whole section in the docs about this:

https://laravel.com/docs/5.2/views#sharing-data-with-all-views

View::share('key', 'value');

If instead you want to remember a certain value to show on the next page, you can always use the session to "flash" data. The documentation has an article about that too:

https://laravel.com/docs/5.2/session#flash-data

Please note that you will need to re-inject these session data into the view, possibly by using the above "share" method on the View facade.

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

6 Comments

Thanks for replying. I will try it out and get back to you and inform you whether it worked or not.
And my issue is that I have a table which consists of user data. I have created a view in which I am able to view the user's name and on clicking on the name I am expecting to view the detailed info of that particular user.
Question is.. Is that detailed information a popup, a new page you visit or something completely different?
I want to show the detailed info on a new view. But information needs to be of the same user on whose hyperlinked name I clicked
Yep, I want to view the info on another page. So, I need to start with session first. Thanks for your help!
|
1

From your question your requirement is not clear.
Am replying specifically to this comment of yours :

Yup right. I have a table which consists of user data. I have created a view in which I am able to view the user's name and on clicking on the name I am expecting to view the detailed info the user. Could you please guide me through the issue? It would be a great help.

When the user clicks the hyper link , pass the user-id to the link. Now , write a controller for this route where you get the user details using the user-id and pass it to the view.

7 Comments

Thanks for replying. So, is there any need of sessions here?
There are many ways to do it , but the easiest is you can attach the id to your route and get it in your controller. From the docs : basic links Route::put('user/{id}', Controller :` 'UserController@update'); public function update(Request $request, $id) { // }`
But how do I attach an id to the route in a view?
<a href= "my-url-link/ . {{$userID}}">
I messed up the formatting of my second comment. It should look like this: Route::put('user/{id}', 'UserController@update'); ` public function update(Request $request, $id) { // }`
|
0

In your view, where you have your php vars you can use:

@include('view.name', ['some' => 'data'])

and now in the 'view.name' you have variable $some contains 'data'

1 Comment

Thanks for replying mate. I want my view to be hyperlinked such that on my first view if there's a click it will be guided to the next view where I will show some related info from the first view..
0

You can pass the variable to another view the same you do in your controller.

Let's say you have this method in your controller:

public function whatever()
{
    $someData = ...
    $otherData = ...

    return view('view', compact('someData', 'otherData));
}

And in your view:

<html>
   <h1>{{ $someData->text }}</h1>
   @include('otherView', ['otherData' => $otherData])
</html>

EDIT:

Note that, otherData will be available anyway in your included views. You don't need to pass it around. The above example is useful if you want to use a different alias to your variable.

3 Comments

Thank You for replying. Yup you are right, but can I pass the variable in the similar manner when I want to get my previous view data to be hyperlinked to the next view.
If i'm understanding correctly you want to pass data between different requests? That's a totally different matter. If you want to save data to be shared between requests you need to save it into a session.
Yup right. I have a table which consists of user data. I have created a view in which I am able to view the user's name and on clicking on the name I am expecting to view the detailed info the user. Could you please guide me through the issue? It would be a great help.
0

Its a long time ago I have created this functionality in which the variable is passed to multiple views.. Here is the code

View::composer('admin.layouts.navbar', function($view){
    $view->with('key', 12);
});

You can paste this code inside routes.php file

Here layout file is /resources/views/admin/layout/navbar and variable name is $key and it can be accessed in navbar view like

{{$key}}

1 Comment

Thanks for replying mate. But my data is never gonna be constant. o/p of the second view will be in accord to the first view o/p.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.