简体   繁体   English

从数据库中选择带有参数的列表

[英]Select List From Database With Parameter

Hi there i have some problem getting list from database using laravel 4.1 嗨,我在使用laravel 4.1从数据库获取列表时遇到了一些问题

I have session that stored some value about companyid. 我的会议存储了一些有关companyid的价值。 Then i want to print the list to table based on the companyid itself. 然后,我想根据companyid本身将列表打印到表中。 Let say i can access the session using {{ Session::get('name')}} 假设我可以使用{{ Session::get('name')}}访问会话

This is my controller index() 这是我的控制器index()

public function index($cid) {

        $pengguna = User::where('id_company', '=', $cid)->get();
        $pengguna->toarray();

        $data = array(
            'pengguna' => $pengguna,
            'page' => 'master',
            'index' => 0
        );

        return View::make('console.pengguna')->with($data);
    }

then i want to print the data to table in view 然后我想将数据打印到视图中的表

                @if($pengguna->count())
                    <table class="table table-striped table-bordered" id="table_pengguna_list">
                        <thead>
                            <tr>
                                <th>No</th>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Username</th>
                                <th>Email</th>
                        <th>Status</th>
                                <th>Last Login</th>
                        <th class="td-actions">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                           @foreach ($pengguna as $pgn)
                           <tr>
                               <td>{{ $index++ }}</td>
                               <td>{{ $pgn->firstname }}</td>
                               <td>{{ $pgn->lastname }}</td>
                               <td>{{ $pgn->username }}</td>
                               <td>{{ $pgn->email }}</td>
                               <td>{{ $pgn->level }}</td>
                               <td>{{ $pgn->updated_at }}</td>
                           </tr>
                           @endforeach
                        </tbody>
                    </table>
           ....

how to pass the parameter from session to the controller then? 然后如何将参数从会话传递到控制器? so basically pass the {{ Session::get('name')}} to $cid in index controller. 因此基本上将{{ Session::get('name')}}传递给索引控制器中的$cid

thank you. 谢谢。

hi there i have found the solution, just place refactor the index controller to; 嗨,我找到了解决方案,只需将索引控制器重构到;

public function index() {
        $cid = Session::get('name');
        $pengguna = User::where('id_company', '=', $cid)->get();
        $pengguna->toarray();

        $data = array(
            'pengguna' => $pengguna,
            'page' => 'master',
            'index' => 0
        );

        return View::make('console.pengguna')->with($data);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM