php - How to save image path into database in Laravel? -
i want upload image , retrieve in database when need this.my code working upload image it's path did not save in database.in database it's showing null
.here code:
if ($request->hasfile('profilepic')) { $file = array('profilepic' => input::file('profilepic')); $destinationpath = 'img/'; // upload path $extension = input::file('profilepic')->getclientoriginalextension(); $filename = rand(11111,99999).'.'.$extension; // renaming image input::file('profilepic')->move($destinationpath, $filename); }else{ echo "please upload profile image!"; } $profile->save();
my question:
- how save image path database?
- and how retrieve image database?
updated: profile.php
class profile extends model { protected $table = "profiles"; public $fillable = ["firstname","lastname","middlename","dob","gender","featuredprofile","email","phone","summary","profilepic"]; }
in code there should this:
$profile->profilepic = $filename;
& then
$profile->save();