Search code examples
mysqllaravellaravel-filesystem

"Call to undefined method Illuminate\Support\Facades\File::save()"


I want stored data in database with image path. I write following function but following error occur.

Call to undefined method Illuminate\Support\Facades\File::save()

which namespace i add?

function insert(Request $req)
   {

       $user=new file;    
       $user->name=Input::get('name');
       $user->address=Input::get('address');
       $user->created_at=Input::get(now());
       $user->updated_at=Input::get(now());

       if(Input::hasFile('image'))
       {
        $file=Input::file('image');
        $file->move(public_path().'/',$file->getClientOriginalName());  
        $user->photo=$file->getClientOriginalName();    
       }

       $user->save();

       return redirect('/');

   }

Solution

  • Try this instead?

    $user = new App\User;
    

    The reason is, in your first line, $user=new file; creates an instance of Illuminate\Support\Facades\File, which does not have a save() method.