dongxing7530 2017-05-09 11:36
浏览 688
已采纳

Laravel 5.2使用.blade视图显示表格

I have my DB, already migrated everything, my code can record new entries in my table when required, and so on.

I have a table with the contents of: 'id', 'name', 'lastname', 'email', 'phone', 'address'.

What I want is, when you hit the submit button, you'll be redirected to a new 'view.blade.php' where you can see all of the DB's entries, including the most recent. BUT I don't know how to develop this code to make it work.

I need help with that, please. Thank you.

  • 写回答

3条回答 默认 最新

  • douci1677 2017-05-09 11:51
    关注

    In your controller function do this right after you store a new record to table. assuming your model name is User

    fetch all user records from User model,

    $users =  App\User::all();
    

    pass this users variable to view(assuming your view.blade.php is in resources/views folder)

    return View::make('view', compact('users'));
    

    and then in your view.blade.php you can do something like this to display all user records.

    <table>
        <thead>
            <tr>
                <th> id</th>
                <th> name</th>
                <th> last name  </th>
                <th> email </th>
                <th> phone</th>
                <th> adddress </th>
            </tr>
        </thead>
        <tbody>
             @foreach($users as $user)
              <tr>
                  <td> {{$user->id}} </td>
                  <td> {{$user->name}} </td>
                  <td> {{$user->last_name}} </td>
                  <td> {{$user->email}} </td>
                  <td> {{$user->phone}} </td>
                  <td> {{$user->address}} </td>
              </tr>
             @endforeach
       </tbody>
    </table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?