Ad

How Can I Upload Profile Pic In Laravel?

In add employee form I have to upload profile pic? is this code is valid?? will anyone help me to modify the code?

This Code Is In My Controller File

$employee = new User();
$file = $request->file('file');
$name = time() . $file->getClientOriginalName();
$file->move('uploads/images', $

$employee->file = $file;
$employee->save();

This IS Code Of My view file

<div class="col-md-6">
     <div class="form-group">
       <label for="photo">Profile Picture :<span class="danger">*</span> </label>
       <input type="file" class="form-control" id="file" name="file">
      </div>
</div>

Issue is that everything work properly but in my collection of mongodb file isn't store. it upload in folder, but not in database.

Ad

Answer

You should change $file variable with $name

$employee->file = $name; // $file may contain file object
$employee->save();
Ad
source: stackoverflow.com
Ad