php - passing variables to laravel service provider -


i want pass variable on laravel app view service provider. view is:

{!! form::open(['url'=>'reports/data',$kpi_id]) !!}      <table class="table table-responsive table-condensed table-bordered tab-content">         <thead>             <tr>                 <th>month</th>                 <th>value</th>             </tr>         </thead>         <tbody>             @foreach($data $dat)                 <tr>{{$dat->month}}</tr>                 <tr>{{$dat->value}}</tr>             @endforeach         </tbody>     </table>  {!! form::close() !!} 

and code @ service provider is:

public function boot() {     $this->composedata(); }  /**  * register application services.  *  * @return void  */ public function register() {     // }  public function composedata() {     view()->composer('reports.data', function ($view, $id) {         $view->with('data', db::table('reports')->where('kpi_id', $id)->orderby('month', 'desc')->take(5)->get());     }); } 

the error:

argument 2 passed app\providers\dataserviceprovider::app\providers\{closure}() must instance of app\http\requests\request, none given 

i tried request still didn't manage make work.

i want know how pass variable view service provider, or @ least how call controller method service provider. tried failed make work. appreciated.

edit

i $id var variable in view

assuming pass $id through route, using router class useful in case. example :

use illuminate\routing\router; // include in serviceprovider  public function boot(router $router) {     $router->bind('id',function($id){ // route:  /reports/{id}         $this->composedata($id);     }); }  public function composedata($id) {   $result = db::table('reports')->where('kpi_id', $id)->orderby('month', 'desc')->take(5)->get()     view()->composer('reports.data', function ($view) use ($result) {     $view->with('data', $result); }); } 

but carefull, view depend on {id} parameter.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -