dimanche 1 décembre 2019

Invalid argument supplied for foreach() (View: E:\xampp\htdocs\web-desa\resources\views\admin\info-admin.blade.php) https://ift.tt/2RaPlEW

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