G
G
Gambi Titto2021-06-05 11:55:19
Laravel
Gambi Titto, 2021-06-05 11:55:19

Why is the data from the Resource Controllers (show) method not displayed on the blade template?

Controller.php

public function show(Open $open)
    {
//        return view('admin.centerPage.center', [
//            'open' => Open::findOrFail($open)
//        ]);
//        return view('admin.centerPage.center')->with('open', $open);
        $open = Open::query()->findOrFail($open);
        return view('admin.centerPage.center', compact('open'));
    }

center.blade.php
<section class="content">
        <div class="card">
            <div class="card-body">
                {{ $open->email }}
                <br>
                Start creating your amazing application!
            </div>
            <div class="card-footer">Footer</div>
        </div>
    </section>

Mistake

Exception
Property [email] does not exist on this collection instance. (View: C:\Users\mylux\Desktop\OpenServer\domains\ADL\adminka\resources\views\admin\centerPage\center.blade.php)

Everything that is commented out in the Controller does not work, the data on the template is not displayed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pLavrenov, 2021-06-05
@pLavrenov

public function show(Open $open)

this line is already loading the desired model, you do not need to somehow get it again.
Route Model Binding

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question