Reputation: 1669
I have table called 'players'. I want to pull every player from the database, or simply select players that have in column 'online' = 1. I want to display their name (column 'name') in 'players' table.
Here's what I've tried:
public function online()
{
$results = Player::with('online')->find(1)
return View::make('aac.test')->with('results', $results);
}
also tried:
public function online()
{
$results = DB::select('select * from players where level = 1');
return View::make('aac.test')->with('results', $results);
}
None of them works.
Upvotes: 0
Views: 8920
Reputation: 3506
public function online()
{
$results = Player::where('level','=','1')->get();
return View::make('aac.test')->with('results', $results);
}
To display it using blade:
<ul>
@foreach($results as $result)
<li>
{{$result->name}}
</li>
@endforeach
</ul>
Upvotes: 0
Reputation: 87719
Try this:
public function online()
{
$results = Player::where('online', 1)->get('name');
return View::make('aac.test')->with('results', $results);
}
To display it using blade:
<ul>
@foreach($results as $result)
<li>
{{$result->name}}
</li>
@endforeach
</ul>
Upvotes: 3