Friday, 15 January 2010

php - Laravel. Keep variable in view during all routes -


I have a very easy problem in Laval 4.2 but I can not solve it. I've got a right-side bar in which there should be some content from my database table during all the routes. I have found the mysql query on the home page page and I pass the variable to see:

  $ query .... Return see: create ('home') - & gt; With ('query', $ query);  

I would like to send this to see 'right-side-bar' for everyone to see, but it has to be identified during all the routes. I have tried to hunt nest, after sharing the variable, but from the time of changing the path, my 'right-side-bar' visible variable can not recognize the query $. I would like to hear some suggestions about how I can solve it. thank you in advanced!

Edit:

Using visual creators

Keep in mind that when you are using visual composers, you should automatically load your files / classes via composer.

Fast dirty route:

  see :: composer ('your-view-name', function ($ view) {$ query = // your query code $ view -> ('query', $ query);});  

or with multiple views:

  View :: Composer (array ('A-View', 'A-Second-View'), Function ($ View) {$ query = // Your query code $ view-> ('query', $ query);});  

Class-based approach ( recommended )

  see: composer ('mine-view', 'MyViewComposerClass');  

then create a class

  class MyViewComposerClass {public function compose ($ view) {$ query = // your query code $ view-> ('query ', Query); }}  

Use of the Base Controller

An easy fix for what you want, something that you have to do in your BaseController constructor .

BaseController.php

  Public function __construct () {$ query = // See your query code: Share ('query' , $ Query); }  

and then make their parent controllers in their constructs such that their second controllers (who clearly expand the bas controller) in this way

< Strong> Other controllers that extend BaseController .php

  public function __ composition () {origin: __ creation (); }  

Then you use the usual variable.

Hope this helps ..

More about Visual Composers:

Laser 5.1:


No comments:

Post a Comment