Can be possible to store a file uploaded to a related table?
Scenario: I have a usres
table in database and another one pictures
. Users Model have the following function
public function picture()
{
return $this->hasOne(Picture::class);
}
And the Picture Model have the following function.
public function user_picture()
{
return $this->belongsTo(User::class, 'user_id', 'id');
}
Is possible to store the picture in pictures
database table (id, user_id, img_path)
from the UserCrudController store()
function?
3
Answers
I resolved the issue with the following steps. As per Laravel Backpack I added the input field in the Blade:
After this I added the function in the User Controller as follow:
With these lines of code I was able to store the related Picture with the User.
Thank you all for the guidelines.
try something like this
Let’s say it is a registration form that need to insert an image. Instead of using the
Picture
model directly you can just do this :