0

I want to upload image but my image can't upload and i check with dd($request->hasFile('supply_photo')); i get return FALSE and i check again with dd($request->all()) i get

"_token" => "ETFJYrRIe6MWqk0LAwXXfBBIHEldHBP4bDeICbpi" 
"item" => "1" 
"tgl_date" => "2019-07-11" 
"use_date" => "2019-07-12" 
"details" => "1" 
"photo" => "A.jpg" ]

I have controller

if($request->hasFile('photo') == true){
                $photo = Validator::make($request->all(), [
                    'photo' => 'image|mimes:jpeg,png,jpg,gif,svg',
                ]);

    if($photo->fails()){
                return redirect()->back()->with('warning', 'Image size should be 2MB or less');
        }            
        $image = $request->file('photo');
        $image_name = rand().'.'. $image->getClientOriginalExtension();
        $destination_path = public_path('/item');
        $image->move($destination_path, $image_name);
    }
        $data->item = $request->item;
        $data->details = $request->details;
        $data->tgl_date = $request->tgl_date;
        //$leave->leave_days = $request->days;
        $data->use_date = $request->use_date;
        $data->id = $id;
        $data->photo = $image_name;
        $data->save();

And my View

 <label for="photo">Photo</label>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" class="form-control" name="photo"> 
ShinAe
  • 1
  • 1
  • You are getting a string in your request (filename) instead of UploadedFile instance. You must check your view for errors. Where is closing form tag? Can you post more data from your view? – Manpreet Jul 12 '19 at 03:31

1 Answers1

-1

In laravel application must be using laravel storage try to visit https://laravel.com/docs/5.8/filesystem

in upload file here is the sample code

use Illuminate\Support\Facades\Storage;
Storage::put('file.jpg', $contents);
xenon
  • 90
  • 4