Level 88
I would probably write a helper function it in some kind of helper file and then you create your function in that file and call it in your view, so something like this should do
// app/Http/helpers.php
function getBackgroundImageForUser($userId)
{
$user = User::findOrFail($userId);
return $user->background_image; // This is the path to the file
}
Now you can do this in your view
Now to make this work you need to autoload the file first in your composer.json
// composer.json
"autoload": {
"files": [
"app/Http/helpers.php"
],
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
You can use this file to add other functions that you want to use on the front end and back end as well ;)
1 like