N
N
naneri2015-02-03 09:04:48
Laravel
naneri, 2015-02-03 09:04:48

Where to set a link to the default image?

Got a question.
There are social network. Users have avatars that they have set, or default ones if they have not.
Now a question. At the moment, the output of the avtarka looks like this:

@if($user->description->user_profile_avatar)
          <img src="{{$user->description->user_profile_avatar}}" alt=""><br>
@else
         <img src="img/default.png" alt=""><br>
@endif

Is this the correct solution? Or is it better to set at the model level that when extracting users, each user with an empty user_profile_avatar is set to a default value?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis, 2015-02-03
@m5web

the concept of "correct / incorrect" does not exist, the solution is quite normal, the blade will do its job in this case, it is actually created for this, if it is implemented at the model level, then the condition will go into the model)))
Proceeding from the logic: the task for the front Yes, this is the best approach

A
Alexey, 2015-02-04
@barsukoff

Well, if the user is initially assigned a picture by default as an avatar? And then output $user->description->user_profile_avatar without any checks. And then transfer the verification logic already at the moment where the user deletes his photo, again replacing the avatar with the default picture.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question