laravel实战项目之用户列表展示

一、管理员管理

1.1 用户列表展示

1、创建控制器

php artisan make:controller Admin/UserController

在这里插入图片描述
UserController.php里写入如下代码:

<?php
// 后台用户管理
namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    // 用户列表
    public function index() {
        return view('admin.user.index');
    }
}

在这里插入图片描述


2、创建模版
views\admin下新建user文件夹,在该文件夹下新建index.blade.phpH-ui.adminmember-list.html
在这里插入图片描述


3、创建用户列表路由

// 用户管理
// 用户列表
Route::get('user/index', 'UserController@index') -> name('admin.user.index');

在这里插入图片描述


4、在页面绑定点击路由
在这里插入图片描述
点击用户列表效果:
在这里插入图片描述


5、用户列表分页
config文件夹下新建page.php
在这里插入图片描述
写入如下代码:

<?php 
return [
    // 页码数
    'pagesize' => 10
];

在这里插入图片描述


创建一个分页控制器:
php artisan make:controller Admin/BaseController
在这里插入图片描述


在分页控制器BaseController.php中写入:

<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class BaseController extends Controller
{ 
    protected $pagesize = 10;
    public function __construct() {
        $this -> pagesize = config('page.pagesize');
    }
}

在这里插入图片描述


在用户控制器UserController.php写入如下代码:

<?php
// 后台用户管理
namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use Faker\Provider\Base;
use App\Models\User;

class UserController extends BaseController
{
    
    // 用户列表
    public function index() {
        // echo $this->pagesize;
        // 分页
        $data = User::paginate($this->pagesize);
        return view('admin.user.index', compact('data'));
    }
}

修改用户列表模版(针对表格循环):

<table class="table table-border table-bordered table-hover table-bg table-sort">
		<thead>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""></th>
				<th width="80">ID</th>
				<th width="100">姓名</th>
				<th width="40">性别</th>
				<th width="90">手机</th>
				<th width="150">邮箱</th>
				<th width="130">加入时间</th>
				<!-- <th width="70">状态</th> -->
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody>
            @foreach($data as $item)
			<tr class="text-c">
				<td><input type="checkbox" value="1" name=""></td>
				<td>{{$item -> id}}</td>
                <td>{{$item -> username}}</td>
				<td>{{$item -> sex == 0 ? '女' : '男'}}</td>
				<td>{{$item -> phone}}</td>
				<td>{{$item -> email}}</td>
				<td>{{$item -> created_at}}</td>
				<!-- <td class="td-status"><span class="label label-success radius">已启用</span></td> -->
				<td class="td-manage"><a style="text-decoration:none" onClick="member_stop(this,'10001')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a> <a title="编辑" href="javascript:;" οnclick="member_edit('编辑','member-add.html','4','','510')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a style="text-decoration:none" class="ml-5" onClick="change_password('修改密码','change-password.html','10001','600','270')" href="javascript:;" title="修改密码"><i class="Hui-iconfont">&#xe63f;</i></a> <a title="删除" href="javascript:;" οnclick="member_del(this,'1')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
			</tr>
            @endforeach
		</tbody>
	</table>

在这里插入图片描述


增加底部分页条:
在这里插入图片描述
在这里插入图片描述
效果:
在这里插入图片描述

在学习的php的路上,如果你觉得本文对你有所帮助的话,那就请关注点赞评论三连吧,谢谢,你的肯定是我写博的另一个支持。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你华还是你华

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值