[英]Display JSON Array in laravel blade
I need to display the JSON data which is inside the column extras_name
individually inside a input boxes with the value filled on edit我需要在输入框中单独显示列
extras_name
内的 JSON 数据,并在编辑时填充值
Here's the blade file codes这是刀片文件代码
<div class="card">
<h5 class="card-header">
Manage Extras
</h5>
<div class="card-body">
{{ $customProduct }}
<br><br><br>
<div class="optionBox">
<div class="block main">
<div class="form-row pb-2">
<div class="col">
<input type="text" class="form-control" name="extras_name[]" value="{{ $customProduct->name }}" placeholder="Name">
</div>
<div class="col">
<input type="text" class="form-control" name="extras_price[]" placeholder="Price">
</div>
<div class="col">
<button type="button" class="remove btn btn-danger"><i class="fas fa-trash-alt"></i></button>
</div>
</div>
<div class="block mt-2 ">
<button type="button" class="add btn btn-success">Add Extras</i></button>
</div>
</div>
</div>
</div>
</div>
Here's the Controller Edit function这是控制器编辑功能
public function edit($venue, CustomProduct $customProduct)
{
$data = [
'customProduct'=>$customProduct,
];
return view('manage.custom-products.edit')->with($data);
}
Here's how the data is saved in the database以下是数据在数据库中的保存方式
first of all json_decode
this首先
json_decode
这个
and then in foreach
you can use that.然后在
foreach
你可以使用它。
Blade File:刀片文件:
@if(!empty(json_decode($data->extras_name))) {{--JUST FOR CHEKING THAT IF THIS WAS NOT JSON OR THIS WAS NULL, THE ERROR NOT SHOWING--}}
@foreach(json_decode($data->extras_name as $title=>$value))
<label>
{{$title ?? ''}} : {{$value ?? ''}}
</label>
<br/>
@endforeach
@endif
这样做没有意义,您可以在输入下方的列表项上显示您的值,并且在添加或删除新值时使用 ajax 刷新列表
If you want to show data in a table then you can use this code如果要在表格中显示数据,则可以使用此代码
` `
@foreach(json_decode($value->extras_name, true) as $extras_name) @foreach(json_decode($value->extras_name, true) as $extras_name)
{{ $extras_name}}
@endforeach @endforeach
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.