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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?