【发布时间】:2020-03-18 01:45:56
【问题描述】:
我有一个属于产品表的特色表(外键 = product_id),现在我想将一些产品 id 保存到我的特色表中,它给了我一个数组结果,但我无法将其保存到数据库中强>
这是我的控制器 -->
public function featuredProduct(Request $request)
{
if($request->isMethod('POST')){
$product_id=$request->all();
foreach ($product_id as $product) {
$products[]=$product;
}
//dd($products);
Featured::create($products);
}
return view('admin.products.featured');
}
<form action="{{ route('featuredProduct') }}" method="POST" multiple>
<table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap verticle_middle">
<thead>
<tr>
<th>Product</th>
<th>Category</th>
<th>Image</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@foreach ($products as $product)
<tr>
<td>
<input id="{{ $product->id }}" value="{{ $product->id }}" type="checkbox" name="product[]">
<label for=id={{ $product->id }}>{{ $product->product_name }}</label>
</td>
<td> {{ $product->category['cat_name'] }} </td>
<td> <img src="{{asset($product->pro_img) }}" alt="" width="40"> </td>
<td class="center">
@if ($product->status === 1)
<span class="btn btn-primary btn-xs">Published</span>
@else
<span class="btn btn-warning btn-xs">Unpublish</span>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="modal-footer">
<button type="button"class="btn btn-default waves-effect" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary waves-effect waves-light">Submit</button>
</div>
</form>
【问题讨论】:
标签: php laravel eloquent laravel-blade