dynamitem
dynamitem

Reputation: 1669

Laravel 4 pulling data from database

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

Answers (2)

iori
iori

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

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

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

Related Questions