Show the output of this in your view
@foreach($inspections as $inspection)
{{ dump($inspection->inspection_data) }}
@endforeach
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I stored my checkboxes in https://www.laracasts.com/discuss/channels/laravel/how-to-store-all-checkboxes-in-laravel site. And I have a question, How to display JSON data in blade.
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
migration for infractions table:
public function up()
{
Schema::create('infractions', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->integer('score');
$table->timestamps();
});
}
migration for inspections table:
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');
});
I want to show title in blade.php. What should I do?
Please or to participate in this conversation.