I have a featureds table (foreign key= product_id) that belongsto products table, Now i want to save some products id to my featured table,its give me a array reasult but i couldnot save it to database
Here is my Controller -->
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>