【发布时间】:2015-07-07 18:53:02
【问题描述】:
我想将我的 laravel 应用程序上的变量从视图传递给服务提供者。 观点是:
{!! 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 as $dat)
<tr>{{$dat->month}}</tr>
<tr>{{$dat->value}}</tr>
@endforeach
</tbody>
</table>
{!! Form::close() !!}
服务提供商处的代码是:
public function boot()
{
$this->composeData();
}
/**
* Register the 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());
});
}
错误:
Argument 2 passed to App\Providers\DataServiceProvider::App\Providers\{closure}() must be an instance of App\Http\Requests\Request, none given
我用 Request 试过了,但还是没能成功。
我想知道如何将变量从视图传递给服务提供者,或者至少如何从服务提供者调用控制器方法。我试过了,但没能成功。感谢所有帮助。
编辑
我从视图中的var 变量中获得$id
【问题讨论】: