0

我有一张名为“玩家”的桌子。我想从数据库中提取每个玩家,或者只是选择“在线”列中的玩家 = 1。我想在“玩家”表中显示他们的名字(“名字”列)。

这是我尝试过的:

    public function online()
{
  $results = Player::with('online')->find(1)
  return View::make('aac.test')->with('results', $results);
}

也试过:

    public function online()
{
  $results = DB::select('select * from players where level = 1');
  return View::make('aac.test')->with('results', $results);
}

它们都不起作用。

4

2 回答 2

3

尝试这个:

public function online()
{
  $results = Player::where('online', 1)->get('name');
  return View::make('aac.test')->with('results', $results);
}

要使用刀片显示它:

<ul>
    @foreach($results as $result)
        <li>
            {{$result->name}}
        </li>
    @endforeach
</ul>
于 2013-07-25T14:36:03.247 回答
0
public function online()
{
  $results = Player::where('level','=','1')->get();
  return View::make('aac.test')->with('results', $results);
}

要使用刀片显示它:

<ul>
    @foreach($results as $result)
        <li>
            {{$result->name}}
        </li>
    @endforeach
</ul>
于 2014-11-22T04:54:00.060 回答