How to Display an Image From a Database in Laravel
up vote
0
down vote
favorite
I have an admin template that I registered into an app from a purchase. The template is very well set up, and parts of it are written in Laravel. I'm able to register new users in my modification, but the user profile image is having problems. When a newly registered user is enacted, the file name is stored in the respective database. However, the image is not able to be displayed. I can even see the image name in the Google Chrome web tools when inspecting the app code. This image is being saved, it's just not displaying on the webpage (at least not on the sidebar).
@if (auth()->user()->profile->pic == null)
<img src="{{asset('storage/uploads/users/no_avatar.jpg')}}" alt="user-img" class="img-circle">
@else
<img src="{{ auth()->user()->profile->pic }}" alt="user-img" class="img-circle">
@endif
If there is something that I'm doing wrong, it must be a basic Laravel issue. I don't know how, but the image must be able to be taken from the database and shown in the view that I pull up or navigate to. If someone could tell me how to properly include the profile pic on the frontend view like any other Laravel app, it would help me a lot. Thank you.
php database laravel laravel-blade avatar
add a comment |
up vote
0
down vote
favorite
I have an admin template that I registered into an app from a purchase. The template is very well set up, and parts of it are written in Laravel. I'm able to register new users in my modification, but the user profile image is having problems. When a newly registered user is enacted, the file name is stored in the respective database. However, the image is not able to be displayed. I can even see the image name in the Google Chrome web tools when inspecting the app code. This image is being saved, it's just not displaying on the webpage (at least not on the sidebar).
@if (auth()->user()->profile->pic == null)
<img src="{{asset('storage/uploads/users/no_avatar.jpg')}}" alt="user-img" class="img-circle">
@else
<img src="{{ auth()->user()->profile->pic }}" alt="user-img" class="img-circle">
@endif
If there is something that I'm doing wrong, it must be a basic Laravel issue. I don't know how, but the image must be able to be taken from the database and shown in the view that I pull up or navigate to. If someone could tell me how to properly include the profile pic on the frontend view like any other Laravel app, it would help me a lot. Thank you.
php database laravel laravel-blade avatar
What exactly are you storing inpic
? Is the image stored in the public folder?
– adam
Nov 10 at 21:33
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have an admin template that I registered into an app from a purchase. The template is very well set up, and parts of it are written in Laravel. I'm able to register new users in my modification, but the user profile image is having problems. When a newly registered user is enacted, the file name is stored in the respective database. However, the image is not able to be displayed. I can even see the image name in the Google Chrome web tools when inspecting the app code. This image is being saved, it's just not displaying on the webpage (at least not on the sidebar).
@if (auth()->user()->profile->pic == null)
<img src="{{asset('storage/uploads/users/no_avatar.jpg')}}" alt="user-img" class="img-circle">
@else
<img src="{{ auth()->user()->profile->pic }}" alt="user-img" class="img-circle">
@endif
If there is something that I'm doing wrong, it must be a basic Laravel issue. I don't know how, but the image must be able to be taken from the database and shown in the view that I pull up or navigate to. If someone could tell me how to properly include the profile pic on the frontend view like any other Laravel app, it would help me a lot. Thank you.
php database laravel laravel-blade avatar
I have an admin template that I registered into an app from a purchase. The template is very well set up, and parts of it are written in Laravel. I'm able to register new users in my modification, but the user profile image is having problems. When a newly registered user is enacted, the file name is stored in the respective database. However, the image is not able to be displayed. I can even see the image name in the Google Chrome web tools when inspecting the app code. This image is being saved, it's just not displaying on the webpage (at least not on the sidebar).
@if (auth()->user()->profile->pic == null)
<img src="{{asset('storage/uploads/users/no_avatar.jpg')}}" alt="user-img" class="img-circle">
@else
<img src="{{ auth()->user()->profile->pic }}" alt="user-img" class="img-circle">
@endif
If there is something that I'm doing wrong, it must be a basic Laravel issue. I don't know how, but the image must be able to be taken from the database and shown in the view that I pull up or navigate to. If someone could tell me how to properly include the profile pic on the frontend view like any other Laravel app, it would help me a lot. Thank you.
php database laravel laravel-blade avatar
php database laravel laravel-blade avatar
edited Nov 11 at 9:57
Karl Hill
1,7491736
1,7491736
asked Nov 10 at 21:29
diggX2414
13
13
What exactly are you storing inpic
? Is the image stored in the public folder?
– adam
Nov 10 at 21:33
add a comment |
What exactly are you storing inpic
? Is the image stored in the public folder?
– adam
Nov 10 at 21:33
What exactly are you storing in
pic
? Is the image stored in the public folder?– adam
Nov 10 at 21:33
What exactly are you storing in
pic
? Is the image stored in the public folder?– adam
Nov 10 at 21:33
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
In order to access your storage path you can use storage_path
helper function instead of asset
so your code should be:
storage_path('uploads/users/no_avatar.jpg');
and for the user that has uploaded picture, if you store the relative path to the picture stored in the public folder then you can use
{{ url(auth()->user()->profile->pic) }}
if the value of auth()->user()->profile->pic
is img/profile.jpg
then you should have img
folder containing profile.jpg
within your project public
directory.
Okay, but what if the data I want is only within a separate database connected to the laravel app? Couldn't it be obtained like the user's name?
– diggX2414
Nov 10 at 23:29
I thought there was a way for the app to display info from a database interaction. It just doesn't seem right to store all users in the storage or public directories.
– diggX2414
Nov 11 at 2:12
the picture has to exists physically on some server in order for you to display it. I don't get your point of the app being able to display info from a database interaction. You can use Amazon S3 service or similar in order to keep the pictures somewhere, but they have to exist. And what you keep in the DB is usually a path to the image, not the image itself.
– nakov
Nov 11 at 8:56
I understand that, but I'm not sure how to select the image. If the path is what is stored in the database, how do I put that exact path in the database?
– diggX2414
Nov 11 at 15:18
laravel.com/docs/5.7/filesystem#file-uploads so from here you store the$path
to the database.
– nakov
Nov 11 at 20:25
|
show 2 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
In order to access your storage path you can use storage_path
helper function instead of asset
so your code should be:
storage_path('uploads/users/no_avatar.jpg');
and for the user that has uploaded picture, if you store the relative path to the picture stored in the public folder then you can use
{{ url(auth()->user()->profile->pic) }}
if the value of auth()->user()->profile->pic
is img/profile.jpg
then you should have img
folder containing profile.jpg
within your project public
directory.
Okay, but what if the data I want is only within a separate database connected to the laravel app? Couldn't it be obtained like the user's name?
– diggX2414
Nov 10 at 23:29
I thought there was a way for the app to display info from a database interaction. It just doesn't seem right to store all users in the storage or public directories.
– diggX2414
Nov 11 at 2:12
the picture has to exists physically on some server in order for you to display it. I don't get your point of the app being able to display info from a database interaction. You can use Amazon S3 service or similar in order to keep the pictures somewhere, but they have to exist. And what you keep in the DB is usually a path to the image, not the image itself.
– nakov
Nov 11 at 8:56
I understand that, but I'm not sure how to select the image. If the path is what is stored in the database, how do I put that exact path in the database?
– diggX2414
Nov 11 at 15:18
laravel.com/docs/5.7/filesystem#file-uploads so from here you store the$path
to the database.
– nakov
Nov 11 at 20:25
|
show 2 more comments
up vote
0
down vote
In order to access your storage path you can use storage_path
helper function instead of asset
so your code should be:
storage_path('uploads/users/no_avatar.jpg');
and for the user that has uploaded picture, if you store the relative path to the picture stored in the public folder then you can use
{{ url(auth()->user()->profile->pic) }}
if the value of auth()->user()->profile->pic
is img/profile.jpg
then you should have img
folder containing profile.jpg
within your project public
directory.
Okay, but what if the data I want is only within a separate database connected to the laravel app? Couldn't it be obtained like the user's name?
– diggX2414
Nov 10 at 23:29
I thought there was a way for the app to display info from a database interaction. It just doesn't seem right to store all users in the storage or public directories.
– diggX2414
Nov 11 at 2:12
the picture has to exists physically on some server in order for you to display it. I don't get your point of the app being able to display info from a database interaction. You can use Amazon S3 service or similar in order to keep the pictures somewhere, but they have to exist. And what you keep in the DB is usually a path to the image, not the image itself.
– nakov
Nov 11 at 8:56
I understand that, but I'm not sure how to select the image. If the path is what is stored in the database, how do I put that exact path in the database?
– diggX2414
Nov 11 at 15:18
laravel.com/docs/5.7/filesystem#file-uploads so from here you store the$path
to the database.
– nakov
Nov 11 at 20:25
|
show 2 more comments
up vote
0
down vote
up vote
0
down vote
In order to access your storage path you can use storage_path
helper function instead of asset
so your code should be:
storage_path('uploads/users/no_avatar.jpg');
and for the user that has uploaded picture, if you store the relative path to the picture stored in the public folder then you can use
{{ url(auth()->user()->profile->pic) }}
if the value of auth()->user()->profile->pic
is img/profile.jpg
then you should have img
folder containing profile.jpg
within your project public
directory.
In order to access your storage path you can use storage_path
helper function instead of asset
so your code should be:
storage_path('uploads/users/no_avatar.jpg');
and for the user that has uploaded picture, if you store the relative path to the picture stored in the public folder then you can use
{{ url(auth()->user()->profile->pic) }}
if the value of auth()->user()->profile->pic
is img/profile.jpg
then you should have img
folder containing profile.jpg
within your project public
directory.
answered Nov 10 at 21:40
nakov
1,44388
1,44388
Okay, but what if the data I want is only within a separate database connected to the laravel app? Couldn't it be obtained like the user's name?
– diggX2414
Nov 10 at 23:29
I thought there was a way for the app to display info from a database interaction. It just doesn't seem right to store all users in the storage or public directories.
– diggX2414
Nov 11 at 2:12
the picture has to exists physically on some server in order for you to display it. I don't get your point of the app being able to display info from a database interaction. You can use Amazon S3 service or similar in order to keep the pictures somewhere, but they have to exist. And what you keep in the DB is usually a path to the image, not the image itself.
– nakov
Nov 11 at 8:56
I understand that, but I'm not sure how to select the image. If the path is what is stored in the database, how do I put that exact path in the database?
– diggX2414
Nov 11 at 15:18
laravel.com/docs/5.7/filesystem#file-uploads so from here you store the$path
to the database.
– nakov
Nov 11 at 20:25
|
show 2 more comments
Okay, but what if the data I want is only within a separate database connected to the laravel app? Couldn't it be obtained like the user's name?
– diggX2414
Nov 10 at 23:29
I thought there was a way for the app to display info from a database interaction. It just doesn't seem right to store all users in the storage or public directories.
– diggX2414
Nov 11 at 2:12
the picture has to exists physically on some server in order for you to display it. I don't get your point of the app being able to display info from a database interaction. You can use Amazon S3 service or similar in order to keep the pictures somewhere, but they have to exist. And what you keep in the DB is usually a path to the image, not the image itself.
– nakov
Nov 11 at 8:56
I understand that, but I'm not sure how to select the image. If the path is what is stored in the database, how do I put that exact path in the database?
– diggX2414
Nov 11 at 15:18
laravel.com/docs/5.7/filesystem#file-uploads so from here you store the$path
to the database.
– nakov
Nov 11 at 20:25
Okay, but what if the data I want is only within a separate database connected to the laravel app? Couldn't it be obtained like the user's name?
– diggX2414
Nov 10 at 23:29
Okay, but what if the data I want is only within a separate database connected to the laravel app? Couldn't it be obtained like the user's name?
– diggX2414
Nov 10 at 23:29
I thought there was a way for the app to display info from a database interaction. It just doesn't seem right to store all users in the storage or public directories.
– diggX2414
Nov 11 at 2:12
I thought there was a way for the app to display info from a database interaction. It just doesn't seem right to store all users in the storage or public directories.
– diggX2414
Nov 11 at 2:12
the picture has to exists physically on some server in order for you to display it. I don't get your point of the app being able to display info from a database interaction. You can use Amazon S3 service or similar in order to keep the pictures somewhere, but they have to exist. And what you keep in the DB is usually a path to the image, not the image itself.
– nakov
Nov 11 at 8:56
the picture has to exists physically on some server in order for you to display it. I don't get your point of the app being able to display info from a database interaction. You can use Amazon S3 service or similar in order to keep the pictures somewhere, but they have to exist. And what you keep in the DB is usually a path to the image, not the image itself.
– nakov
Nov 11 at 8:56
I understand that, but I'm not sure how to select the image. If the path is what is stored in the database, how do I put that exact path in the database?
– diggX2414
Nov 11 at 15:18
I understand that, but I'm not sure how to select the image. If the path is what is stored in the database, how do I put that exact path in the database?
– diggX2414
Nov 11 at 15:18
laravel.com/docs/5.7/filesystem#file-uploads so from here you store the
$path
to the database.– nakov
Nov 11 at 20:25
laravel.com/docs/5.7/filesystem#file-uploads so from here you store the
$path
to the database.– nakov
Nov 11 at 20:25
|
show 2 more comments
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243585%2fhow-to-display-an-image-from-a-database-in-laravel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What exactly are you storing in
pic
? Is the image stored in the public folder?– adam
Nov 10 at 21:33