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 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题