1 year ago

How to save upload image to directory in laravel 5.8

Posted 1 year ago by adhik13th

i have a function to upload images , this upload type is json . this json like this :

"pertanyaan" => "{"question1":"Kondisi, kebersihan, pelumasan bearing","answer1":"baik","image":"gambar.png"} ◀"

on this json have a key value = image : gambar.png . this name of image is saved into json . and the problem is i cant saved this image (gambar.png) into directory file on folder . my input:

<td> <input class="form-control" style="border:none"  type="file" name="image" value="" readonly> </td>

its my controller :

public function store(Request $request)

        foreach($request->file('image') as $file)
            $file->move(public_path().'/images/', $name);  
            $data = $name;  

    $user = new pemeliharaan;
    $id = Auth::user()->id;

    $user->user_id = $id;
    $user->alat_id = $request->alat_id;
    $user->pertanyaan =json_encode($request->except
    (['_token','name','alat_id','status','catatan']));//this image on here
    $user->catatan = $request->catatan;
    $user->status = $request->status;

    return redirect('user/show6')->with('success', 'Data Telah Terinput');


I am create a folder images at public. can someone correct my code to saved file(image) ?

Please sign in or create an account to participate in this conversation.