简体   繁体   中英

Can't save .png ext in database in laravel

I'm sorry I can't upload png image to database using laravel but jpg uploaded successfully, validation don't work if I deleted the validation give me the below error, thanks in advances.

SQLSTATE[HY000]: General error: 1364 Field 'businessimg' doesn't have a default value

public function storefiles(Request $request)
{
    $this->validate($request, [
    'file' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:9048',
]);  
    $addfiles= new Files();
    $addfiles->appo_id = $request->input('Appoid');
    if($request->hasFile('file'))
    {
       $file = $request->file('file');
       $filename = time().'.'.$file->getClientOriginalExtension();
      Image::make($file)->save(public_path('Admin/BusinessCards/'.$filename));
       $addfiles->businessimg = $filename;
  }
   $addfiles->save(); 
   return redirect()->back(); 
 }

My HTML:

<form class=""  action="{{url('storefiles')}}"  role="form" enctype="multipart/form-data" method="POST">
{!! csrf_field() !!}
 <input type="hidden" name="_method" value="PUT">      
        <input type="hidden" name="Appoid" value="{{$addfiles->id}}">
      <label for="File">File :</label>
    <input type="File" name="file">
   <input class="btn btn-success btn-mini deleteRecord" type="submit" name="submit" value="Upload">
   </form>

Use it

$file->save(public_path('Admin/BusinessCards/'.$filename));

Instead of it

Image::make($file)->save(public_path('Admin/BusinessCards/'.$filename));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM