我正在使用这个库:https ://www.laravelplay.com/packages/ycs77::laravel-wizard我完成了所有步骤并得到了与示例中相同的结果。我试图从数据库中获取数据到每个步骤。型号(App/steps/intro/DropboxStep.php):<?phpnamespace App\Steps\Intro;use Illuminate\Http\Request;use Ycs77\LaravelWizard\Step;use DB;class DropboxStep extends Step{ /** * The step slug. * * @var string */ protected $slug = 'dropbox'; /** * The step show label text. * * @var string */ protected $label = 'Dropbox'; /** * The step form view path. * * @var string */ protected $view = 'steps.intro.dropbox'; /** * Set the step model instance or the relationships instance. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Relations\Relation|null */ public function model(Request $request) { // } /** * Save this step form data. * * @param \Illuminate\Http\Request $request * @param array|null $data * @param \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Relations\Relation|null $model * @return void */ public function saveData(Request $request, $data = null, $model = null) { // } /** * Validation rules. * * @param \Illuminate\Http\Request $request * @return array */ public function rules(Request $request) { return []; } public function getOptions() { $stepa2 = DB::table('tutorials')->where('id', '2')->first(); return [ 'stepa2' => $stepa2, 'Lucas', ]; }}看法:<div class="form-group"> {{ $stepa2 }}</div>结果:未定义的变量:stepa2也通过控制器尝试过(IntroWizardController.php)
1 回答
www说
TA贡献1775条经验 获得超8个赞
要将任何数据从控制器传递到刀片视图,只需使用这两个选项
选项1:
public function someFunction()
{
$model = DB::table('model_table')->where('id', '2')->first();
return view('blade_view_name', compact('model'));
}
选项 2:
public function someFunction()
{
$model = DB::table('model_table')->where('id', '2')->first();
return view('blade_view_name')->with('model', $model);
}
如果你有更多或想要更多的变量,你可以像这样链接 with() 方法:
return view('blade_view_name')
->with('model', $model)
->with('variable', 'Some other variable');
- 1 回答
- 0 关注
- 82 浏览
添加回答
举报
0/150
提交
取消