A
A
Alexander Sharomet2016-10-27 09:40:37
Laravel
Alexander Sharomet, 2016-10-27 09:40:37

How to display data in laravel without foreach in view?

Hi all.
Is it possible to display data in a view so that we don't have to use a foreach loop?
example
Model

...
$users = Settings::All();

return $this->renderContent(
    view('admin.settings.index',compact('users')),
    trans('Users')
);
....

View
@foreach($users as $user)
<h3>{{ $user['name'] }}</h3>
@endforeach

Only one user will be displayed here at all times, that is, the foreach construct is generally unnecessary.
Is there any method that will immediately return the desired data?
like
$users = Settings::All()->foreach;
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor, 2016-10-27
@sharomet

If there is always one entry in Settings, then Settings::first() will return the first (and only) entry.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question