I want to upload an image and retrieve in from database when i need this.My code is perfectly working to upload image but it's path did not save in database.In database it's showing Null.Here is my 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 Your Profile Image!";
}
$profile->save();
My Question:
Updated: Profile.php
class Profile extends Model
{
protected $table = "profiles";
public $fillable = ["firstName","lastName","middleName","DOB","gender","featuredProfile","email","phone","summary","profilePic"];
}
In your code there should be like this:
$profile->profilePic = $fileName;
& then
$profile->save();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With