<?php
use Illuminate\Support\Facades\Route;
use Illuminate\http\Middleware;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
//Route::get('/', function () {
// return view('welcome');
//});
Route::prefix('loge')->group(function (){
Route::any('loge','logeController@loge')->name('loge');
Route::any('logging','logeController@logging')->name('logging');
});
Route::prefix('admin')->group(function (){
Route::any('form','UserController@form')->name('form')->middleware('CheckLog');
Route::any('add','UserController@add')->name('add');
Route::any('show','UserController@show')->name('show');
Route::any('del','UserController@del')->name('del');
Route::any('upShow','UserController@upShow')->name('upShow');
Route::any('upShow','UserController@upShow')->name('upShow');
Route::any('upData','UserController@upData')->name('upData');
Route::any('huishouzhan','UserController@huishouzhan')->name('huishouzhan');
Route::any('cd','UserController@cd')->name('cd');
Route::any('hf','UserController@hf')->name('hf');
});
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreBlogPost;
use App\models\loge;
use Illuminate\Http\Request;
use Illuminate\http\Middleware;
use Illuminate\Support\Facades\Auth;
use MongoDB\Driver\Session;
class logeController extends Controller
{
public function loge()
{
return view('loge');
}
public function logging(StoreBlogPost $request)
{
$data = $request->validated();
$uname = $request->input('uname');
$pwd = $request->input('pwd');
$obj = new loge();
$res = $obj->loge($uname);
$arr = json_decode(json_encode($res),true);
if ($arr['uname']==$uname)
{
if ($arr['pwd']==$pwd)
{
return view('form');
}else
{
return view('loge')->withErrors('密码错误');
}
}else{
return view('loge')->withErrors('账号错误');
}
}
}
<?php
namespace App\models;
use Illuminate\Database\Eloquent\Model;
class loge extends Model
{
protected $table = 'loge';
public $timestamps = false;
public function loge($uname)
{
return $this->where('uname',$uname)->first();
}
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<form action="{{ route('logging') }}" method="post" enctype="multipart/form-data">
@csrf
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
<div class="form-group">
<label for="email">账号</label>
<input type="text" class="form-control" name="uname">
</div>
<div class="form-group">
<label for="pwd">密码</label>
<input type="password" class="form-control" name="pwd">
</div>
<div class="row">
<div class="col-md-8">
<input type="text" class="form-control {{$errors->has('captcha')?'parsley-error':''}}" name="captcha" placeholder="captcha">
</div>
<div class="col-md-4">
<img src="{{captcha_src()}}" style="cursor: pointer" onclick="this.src='{{captcha_src()}}'+Math.random()">
</div>
@if($errors->has('captcha'))
<div class="col-md-12">
<p class="text-danger text-left"><strong>{{$errors->first('captcha')}}</strong></p>
</div>
@endif
</div>
<button type="submit" class="btn btn-primary">登录</button>
</form>
</div>
</body>
</html>
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreBlogPosts;
use App\models\user;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function __construct()
{
$this->middleware('CheckLog',[
'only'=>['edit','update']
]);
}
public function form()
{
return redirect('admin/form');
}
public function add(StoreBlogPosts $request)
{
$data = $request->validated();
$data['img'] = $request->file('img')->store('img');
$obj = new user();
$res = $obj->add($data);
if ($res)
{
echo "<script>alert('添加成功');location.href='".route('show')."'</script>";
}
else
{
echo "<script>alert('添加失败');location.href='".route('form')."'</script>";
}
}
public function show(Request $request)
{
$uname = $request->input('uname');
$arr1 = [];
$arr2 = [];
if (!empty($uname))
{
array_push($arr1,['uname','like','%$uname%']);
$arr2['uname'] = $uname;
}
$obj = new user();
$res = $obj->show($arr2);
return view('show',compact('res'),['arr2'=>$arr2]);
}
public function del(Request $request)
{
$id = $request->input('id');
$obj = new user();
$res = $obj->del($id);
if ($res)
{
echo json_encode(['code'=>'200','msg'=>'成功','data'=>$res]);
}
}
public function upShow()
{
$id = request()->get('id');
$obj = new user();
$res = $obj->upShow($id);
return view('upShow',compact('res'));
}
public function upData()
{
$data = request()->post();
unset($data['_token']);
$id = request()->get('id');
$obj = new user();
$res = $obj->upData($id,$data);
if ($res)
{
echo "<script>alert('修改成功');location.href='".route('show')."'</script>";
}
else
{
echo "<script>alert('修改失败');location.href='".route('show')."'</script>";
}
}
public static function huishouzhan()
{
$res = user::huishouzhan();
return view('huishouzhan',['res'=>$res]);
}
public static function cd(Request $request)
{
$id = $request->get('id');
user::cd($id);
return redirect('admin/show');
}
public static function hf(Request $request)
{
$id = $request->get('id');
user::hf($id);
return redirect('admin/show');
}
}
<?php
namespace App\models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class user extends Model
{
use SoftDeletes;
protected $table = 'users';
public $timestamps = false;
public function add($data)
{
return $this->insert($data);
}
public function show($data)
{
return $this->where($data)->paginate(3);
}
public function del($id)
{
return $this->whereIn('id',$id)->delete();
}
public function upShow($id)
{
return $this->where('id',$id)->first();
}
public function upData($id,$data)
{
return $this->where('id',$id)->update($data);
}
public static function huishouzhan()
{
return self::onlyTrashed()->paginate(3);
}
public static function cd($id)
{
return self::onlyTrashed()->find($id)->forceDelete();
}
public static function hf($id)
{
return self::onlyTrashed()->find($id)->restore();
}
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<form action="{{route('add')}}" method="post" enctype="multipart/form-data">
@csrf
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
<div class="form-group">
<label for="email">上传图像</label>
<input type="file" class="form-control" name="img">
</div>
<div class="form-group">
<label for="email">真实姓名</label>
<input type="text" class="form-control" name="uname">
</div>
<div class="form-group">
<label for="email">昵称</label>
<input type="text" class="form-control" name="name">
</div>
<div class="form-group">
<label for="email">性别</label>
<input type="text" class="form-control" name="sex">
</div>
<div class="form-group">
<label for="email">手机号</label>
<input type="text" class="form-control" name="tel">
</div>
<div class="form-group">
<label for="email">出生日期</label>
<input type="datetime-local" class="form-control" name="begintime">
</div>
<label for="email">状态</label>
<div class="radio">
<label><input type="radio" name="on" value="正常">正常</label>
<label><input type="radio" name="on" value="不正常">不正常</label>
</div>
<div class="form-group">
<label for="email">城市</label>
<input type="text" class="form-control" name="city">
</div>
<div class="form-group">
<label for="email">评论</label>
<input type="text" class="form-control" name="text">
</div>
<div class="form-group">
<label for="email">简介</label>
<input type="text" class="form-control" name="utext">
</div>
<button type="submit" class="btn btn-primary">添加</button>
</form>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<a href="{{ route('show') }}">回到展示页面</a>
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>真实姓名</th>
<th>用户昵称</th>
<th>性别</th>
<th>用户头像</th>
<th>状态</th>
<th>手机号码</th>
<th>所在地区</th>
<th>设备类型</th>
<th>用户来源</th>
<th>注册时间</th>
<th>功能操作</th>
</tr>
</thead>
<tbody>
@foreach($res as $v)
<tr>
<td>{{$v['id']}}</td>
<td>{{$v['uname']}}</td>
<td>{{$v['name']}}</td>
<td>{{$v['sex']}}</td>
<td><img src="{{ asset($v['img']) }}" alt="" width="50px" height="50px"></td>
<td>{{$v['on']}}</td>
<td>{{$v['tel']}}</td>
<td>{{$v['city']}}</td>
<td>未知</td>
<td>注册会员</td>
<td>{{$v['begintime']}}</td>
<td><a href="{{ route('cd') }}?id={{ $v['id'] }}">清除</a> <a href="{{ route('hf') }}?id={{ $v['id'] }}">恢复</a></td>
</tr>
@endforeach
</tbody>
</table>
{{$res->links()}}
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<form action="{{ route('show') }}" method="post">
@csrf
<input type="text" name="uname">
<button type="submit">
搜索
</button>
</form>
<table class="table">
<thead>
<a href="{{ route('form') }}">添加</a>
<button id="dellSure">批量删除</button>
<tr>
<th></th>
<th>ID</th>
<th>真实姓名</th>
<th>用户昵称</th>
<th>性别</th>
<th>用户头像</th>
<th>状态</th>
<th>手机号码</th>
<th>所在地区</th>
<th>设备类型</th>
<th>用户来源</th>
<th>注册时间</th>
<th>功能操作</th>
</tr>
</thead>
<tbody>
@foreach($res as $v)
<tr>
<td><input type="checkbox" class="checks" value="{{ $v['id'] }}"></td>
<td>{{$v['id']}}</td>
<td>{{$v['uname']}}</td>
<td>{{$v['name']}}</td>
<td>{{$v['sex']}}</td>
<td><img src="{{ asset($v['img']) }}" alt="" width="50px" height="50px"></td>
<td class="dg">{{$v['on']}}</td>
<td>{{$v['tel']}}</td>
<td>{{$v['city']}}</td>
<td>未知</td>
<td>注册会员</td>
<td>{{$v['begintime']}}</td>
<td><a href="javascript:;" class="aaa" id="{{ $v['id'] }}">删除 </a>
<a href="{{ route('upShow') }}?id={{ $v['id'] }}">修改</a></td>
<td>
<button>
<a href="{{ url('admin/huishouzhan') }}">回收站</a>
</button>
</td>
</tr>
@endforeach
</tbody>
</table>
{{$res->appends($arr2)->links()}}
</div>
</body>
</html>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
</script>
<script>
$('.aaa').click(function () {
var id =$(this).attr('id');
var _this=$(this);
$.ajax({
url:'del',
data:{id:id},
type:'get',
dataType:'json',
success:function (res) {
if (res['code']=='200')
_this.parents('tr').remove();
}
})
})
$('.dg').click(function () {
if($(this).text()=='正常'){
$(this).text()==$(this).text('不正常');
}else{
$(this).text()==$(this).text('正常');
}
})
$('#dellSure').click(function (){
var id=[];
$('.checks:checked').each(function (){
id.push($(this).val());
})
$.ajax({
url:'del',
data:{id:id},
type:'get',
dataType:'json',
success:function (res) {
if (res['code']=='200')
$('.checks:checked').each(function () {
$(this).parents('tr').remove()
})
}
})
})
</script>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<form action="{{route('upData')}}?id={{ $res['id'] }}" method="post" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label for="email">上传图像</label>
<input type="file" class="form-control" name="img">
</div>
<div class="form-group">
<label for="email">真实姓名</label>
<input type="text" class="form-control" name="uname" value="{{$res['uname']}}">
</div>
<div class="form-group">
<label for="email">昵称</label>
<input type="text" class="form-control" name="name" value="{{$res['name']}}">
</div>
<div class="form-group">
<label for="email">性别</label>
<input type="text" class="form-control" name="sex" value="{{$res['sex']}}">
</div>
<div class="form-group">
<label for="email">手机号</label>
<input type="text" class="form-control" name="tel" value="{{$res['tel']}}">
</div>
<div class="form-group">
<label for="email">出生日期</label>
<input type="datetime-local" class="form-control" name="begintime" value="{{$res['begintime']}}">
</div>
<label for="email">状态</label>
<div class="radio">
<label><input type="radio" name="on" value="正常">正常</label>
<label><input type="radio" name="on" value="不正常">不正常</label>
</div>
<div class="form-group">
<label for="email">城市</label>
<input type="text" class="form-control" name="city" value="{{ $res['city'] }}">
</div>
<div class="form-group">
<label for="email">评论</label>
<input type="text" class="form-control" name="text" value="{{ $res['text'] }}">
</div>
<div class="form-group">
<label for="email">简介</label>
<input type="text" class="form-control" name="utext" value="{{ $res['utext'] }}">
</div>
<button type="submit" class="btn btn-primary">添加</button>
</form>
</div>
</body>
</html>
|