1

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('/');

   }
Dhruv Raval
  • 1,535
  • 1
  • 8
  • 15
seema
  • 344
  • 1
  • 3
  • 11

3 Answers3

3

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.

hktang
  • 1,745
  • 21
  • 35
0

you can use File aliases in top of controller Illuminate\Support\Facades\File::class,

$move = File::move($old_path, $new_path);

File is for save file in directory and you can you instance of user for save user data

$user = New App\User();
manish
  • 81
  • 1
  • 7
0

try to just changed here

$user=new file;

to

$user = new User();
Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57