Answer the question
In order to leave comments, you need to log in
How can static data be redefined from the database?
There is certain data that numbers come in, but I need to make sure that these numbers change immediately to a value. I tried to look at the mutators, but I didn’t catch up, it’s possible to somehow apply them to the data.
Here's how
$shedules = Shedule::where('user_id', $user)->where('date', strtotime(date('Y-m-d')))->get();
foreach ($shedules as $shedule){
$shedule->type = $shedule->type == 1 ? 'Групповое занятие' : 'Индивидульные занятие'; // Вот эти моменты часто повторяются
}
Answer the question
In order to leave comments, you need to log in
If you read the documentation carefully before you start writing, and judging by your question, you seem to have read, but did not bother to understand.
You can add a method to your model, either under the same name type, or make it more readable to name it type_name, in order to do this you just need to add a reader
public function getTypeNameAttribute()
{
return $this->type == 1 ? 'Групповое занятие' : 'Индивидулаьные занятие';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question