Level 4
The all() method returns a collection, not a model. So you have to iterate over the collection and and do the merge on the model (or write an accessor on your model)
For example:
$data = Table::all()->sortByDesc('date')->map(function ($model) {
$model->dateMerged = $model->date . ' ' . $model->time;
return $model;
});
return view('welcome')->with(compact('data'));
You could do it in the view as well:
$data = Table::all()->sortByDesc('date');
return view('welcome')->with(compact('data'));
Blade:
@foreach($data as $item)
<p>{{$item->date}} {{$item->time}}</p>
@endforeach
As an accessor on the model:
(Model Table)
public function getDateMergedAttribute()
{
return $this->date . ' ' . $this->time;
}
Now you would have a date_merged attribute on each model instance