Как мне проанализировать эти данные JSON в представлении лезвия? - PullRequest
0 голосов
/ 24 октября 2018

Я сохранил свои флажки на https://www.laracasts.com/discuss/channels/laravel/how-to-store-all-checkboxes-in-laravel сайте.И у меня есть вопрос, как отобразить данные JSON в блейде.

JSON

InspectionController.php

public function index()
{
    $inspections = Inspection::latest()->where('inspection_data', 1)->get();
    return view('Admin.infractions.all', compact('inspections'));
}

Inspection.php

public function inspections()
{
    return $this->belongsTo(Inspection::class, 'inspection_data');
}

all.blade.php

@foreach($inspections as $inspection)
    <tr>
        <td>{{ $inspection->inspection_data->id }}</td>
        <td>{{ $inspection->inspection_data->title }}</td>
    </tr>
@endforeach 

миграция для таблицы нарушений:

public function up()
{
    Schema::create('infractions', function (Blueprint $table) {
        $table->increments('id');
        $table->string('title');
        $table->integer('score');
        $table->timestamps();
    });
}

миграция для таблицы проверок:

public function up()
{
    Schema::create('inspections', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id')->unsigned();
        $table->integer('requisition_id')->unsigned();
        $table->string('encouragement_data')->nullable(true);
        $table->text('infraction_data')->nullable(true);
        $table->timestamps();

        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->foreign('requisition_id')->references('id')->on('requisitions')->onDelete('cascade');
    });

Я хочу показать title в blade.php.Что мне делать?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...