Answer the question
In order to leave comments, you need to log in
Should Blade use this design?
Everyone advises to use Blade to the maximum. Here I have a condition, to use it this way or all the same in a native way through <?php ?>. The if shorthand does not need to be offered, since the variable assignment code is long, for example:
$UserPhoto = '/images/user_profile/'.\App\Models\Question::find($quest_id)->user->UserPhoto->image_url .'.jpg';
Here's how it is now through Blade:
@if( $a == $b )
{{-- */ $a = 1 /* --}}
@else
{{-- */ $a = 0 /* --}}
@endif
Answer the question
In order to leave comments, you need to log in
I don’t know which solution is more logical, but I did the following:
In order to avoid constant access to the database for information about the user and to the table for the photo, I used:
As a result , an array of 3 tables is formed in $AllQuestions .
In the Question
model
I did the following:
class Question extends Model
{
//
public function user()
{
return $this->belongsTo('App\User');
}
public function file(){
return $this->hasOne('App\Models\File','user_id','user_id')->where('module_id', 'user_profile');
}
}
In blade files, only blade constructs. Most of the logic, especially assigning any values to variables, is still recommended to be performed before rendering the view (View) and outside of it, so as not to complicate.
In fact, just prepare the necessary variables in the controller, pass them to the view:
$a = ($a == $b) ? 1 : 0;
return render('someview')->with(['a' => $a]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question