我的复选框存储在https://www.laracasts.com/discuss/channels/laravel/how-to-store-all-checkboxes-in-laravel网站中。我有一个问题,如何在刀片中显示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');
});
我想在Blade.php中显示title
。我该怎么办?