lundi 31 octobre 2016

Laravel 5.3 image upload issue

I am new to laravel 5.3. I need to upload the image to the database table spare. Here is my controller. The error i am getting is also attached.Please help thanks in advance.

 public function store(Request $request)
{
    try{
        $Spare=new Spares;
        $Spare->model_id=$request->get('modelId');
        $Spare->brand_id=$request->get('brandId');
        $Spare->partNumber=$request->get('partNumber');
        $Spare->warranty=$request->get('warranty');
        $Spare->retailer_id=$request->get('retailerId');
        $Spare->quantity=$request->get('quantity');
        $Spare->price=$request->get('price');
        $Spare->description=$request->get('description');
        $file = $request->file('image');

        // Get the contents of the file
        $contents = $file->openFile()->fread($file->getSize());

        $Spare->image=$contents;

        $Spare->save();
        \Session::flash('flash_message','Added new Spare.'); //<--FLASH MESSAGE

        return redirect()->back();
    }
    catch (\Illuminate\Database\QueryException $ex){
        dd($ex->getMessage());
    }
}

I am getting this error.

enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire