Laravel 4.2 DB返回所有记录

时间:2015-08-12 16:33:39

标签: php database laravel

我正在使用Laravel 4.2并从数据库中捕获单个数据,因为foreach循环始终为我提供了最后一条记录

这是我的blade.php文件中的foreach:

    @foreach($vrataMreze as $vrataMrezeVar)
        <tr>
            <td>{{ $vrataMrezeVar->nalogBroj }}</td>
            <td>{{ $vrataMrezeVar->nazivNaloga }}</td>
            <td>{{ $vrataMrezeVar->narucitelj }}</td>
            <td>{{ $vrataMrezeVar->datumIzrade }}</td>
            <td>{{ $vrataMrezeVar->statusProizvodnje }}</td>
            <td>{{ $vrataMrezeVar->datumOtpreme }}</td>
            <td>{{ $vrataMrezeVar->nacinOtpreme }}</td>
            <td>{{ $vrataMrezeVar->statusPoslovnice }}</td>
            <td>{{ $vrataMrezeVar->datumMontaze }}</td>
            <td>{{ $vrataMrezeVar->montirano }}</td>
            <td>{{ $vrataMrezeVar->isporuceno }}</td>
            <td align="center"><span class="glyphicon glyphicon-ok"></span></td>
            <td align="center"><span class="glyphicon glyphicon-trash"></span></td>
            <td align="center"><span class="glyphicon glyphicon-edit"></span></td>
            <td align="center"><a href="{{ URL::route('openVrataMreza', $vrataMrezeVar->id);  }} " target="_blank" ><span class="glyphicon glyphicon-eye-open"></span></a></td>                                         
        </tr>

此行动的路线:

Route::get('/nalozi/mreze/vrataMrezaOpen', array('uses' => 'MrezeController@openVrataMreza', 'as' => 'openVrataMreza'));

来自我的控制器的功能:

public function openVrataMreza($id)
    {
        $vrataMreze = DB::table('VrataMreza')->where('id', $id)->first();
        return View::make('nalozi.Mreze.Vrata_Mreze.vrataMrezaOpen')->with('vrataMreze', $vrataMreze);
    }   

我也试过

 Session::set('id', $vrataMrezeVar->id);

 Session::get('id');

但没有用,aslo从数据库中获取最后一条记录..

1 个答案:

答案 0 :(得分:0)

您的问题不太清楚,但要获得最后一条记录,您可以修改雄辩的查询。

 public function openVrataMreza($id)
{
    $vrataMreze = DB::table('VrataMreza')->where('id', $id)->orderBy('id','DESC')->first();
    return View::make('nalozi.Mreze.Vrata_Mreze.vrataMrezaOpen')->with('vrataMreze', $vrataMreze);
}