Laravel模型传递给查看

Im using this library: https://www.laravelplay.com/packages/ycs77::laravel-wizard

我完成了所有步骤,并得到与示例相同的结果。

我试图从数据库获取数据到每个步骤。

模型(App / steps / intro / DropboxStep.php):

<?php

namespace 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)

这是默认控制器:

<?php

namespace App\Http\Controllers;

use App\Steps\Intro\DropboxStep;
use App\Steps\Intro\H2NStep;
use App\Steps\Intro\PT4Step;
use Ycs77\LaravelWizard\Wizardable;
use DB;



class IntroWizardController extends Controller
{
    use Wizardable;

    /**
     * The wizard name.
     *
     * @var string
     */
    protected $wizardName = 'intro';

    /**
     * The wizard title.
     *
     * @var string
     */
    protected $wizardTitle = 'Intro';

    /**
     * The wizard options.
     *
     * @var array
     */
    protected $wizardOptions = [];

    /**
     * The wizard steps instance.
     *
     * @var array
     */
    protected $steps = [
        DropboxStep::class,
        H2NStep::class,
        PT4Step::class,
    ];

}

我补充说:

public function getOptions()
    {

        $stepa2 = DB::table('tutorials')->where('id', '2')->first();

        return [
            'stepa2' => $stepa2,
            'Lucas',
        ];
    }

也在控制器返回视图中尝试过,但是随后我从数据库中的空白页(而不是其他部分)中获取结果。

是否可以通过数据库查询以使用此库进行查看? 谢谢

评论