invalid argument supplied foreach()when try to add data
here's the form for submitting the data
info-admin.blade
<tbody class="text-center align-middle">
@foreach ( $info as $infos )
<tr>
<th scope="row" class="align-middle"></th>
<td class="align-middle"></td>
<td class="align-middle"></td>
<td class="align-middle"></td>
<td class="align-middle"></td>
<td class="align-middle"></td>
<td class="align-middle form">
<a href=""><button type="submit" class="btn btn-info mb-3">Edit</button></a>
<form method="POST" action="">
<button type="submit" class="btn btn-danger">Hapus</button>
</form>
</td>
</tr>
@endforeach
</tbody>
Store logic
InfosController
public function store(Request $request)
{
$info = new Info();
$info->judul = $request->input('judul');
$info->konten = $request->input('konten');
$info->image = $request->input('image');
if($request->hasFile('image')){
$file = $request->file('image');
$extension = $file->getClientOriginalExtension();
$filename = time() . '.' . $extension;
$file->move('upload/info_penting' , $filename);
$info->image = $filename;
} else{
return $request;
$info->image = '';
}
$info->save();
return view('admin.info-admin')->with('info','$info');
}
my routes, incase if you want to see it
web.php
route::post('/tambah-info','InfosController@store')->middleware('auth','admin');
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire