S
S
Sasha Ermolaev2020-02-06 16:32:00
Laravel
Sasha Ermolaev, 2020-02-06 16:32:00

How to display data from a table using Laravel via QueryBuilder or Raw Query?

There was a problem when displaying data from the database, what could be the error?

Marchut

Route::get('/', function () {
  $users = DB::table('client')->get();
  return view('welcome',compact('client'));
});

welcome page
<ul>
  @foreach
       ($users as $user) 
          <li>{{ $user->fio}}</li>
      @endforeach
      </li>

Table client
5e3c15236876a360963530.png

Error
5e3c1673adda3729082767.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2020-02-06
@Nc_Soft

compact('client') replace with compact('users')

S
serginhold, 2020-02-06
@serginhold

Who will transfer users to the template?
And foreach on one line with brackets.
Copy the documentation and compare.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question