普通用户需要管理员批准才能在Laravel项目中注册

时间:2017-04-24 21:40:34

标签: php laravel-5

在我的Laravel项目中,我想添加一个管理员批准表单,用户可以成功注册。 目前我的users表中有一个布尔列,默认情况下分配为false。 当用户注册时,它会显示一条消息"感谢您注册...等待批准。" 我可以使用" PHP工匠修补器"手动将布尔值更改为true,但是,我希望管理员从管理仪表板批准。 在我的用户列表页面下的管理信息中心,我可以显示两个表格,一个用于已批准的用户,另一个用于未批准的用户。

@extends('layouts.app')
@section('content')
<div id="wrapper" class="active">

   <!-- Sidebar -->
  <div id="sidebar-wrapper">
    <ul id="sidebar_menu" class="sidebar-nav">
     <li class="sidebar-brand">menu</li>
    </ul>
   @include('includes.admin-sidebar')
</div>

<!-- Page content -->
<div id="page-content-wrapper">
<!-- Keep all page content within the page-content inset div! -->
<div class="page-content inset">
  <div class="row">
    <div class="col-xs-12">
      @foreach ($users as $user)
      <table class="table table-striped">
        <thead>
          <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Date Created</th>
            <th>Approve Login</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>{{$user->name}}</td>
            <td>{{$user->email}}</td>
            <td>{{$user->created_at}}</td>
            <td><button type="button" class="btn btn-primary" onclick="approveUser()">Approve</button></td>
          </tr>
        </tbody>
      </table>
      @endforeach
    </div>
  </div>
  <div class="row">
    <div class="col-xs-12">
      @foreach ($usersApproved as $userap)
      <table class="table table-striped">
        <thead>
          <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Date Created</th>
            <th>Approve Login</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>{{$userap->name}}</td>
            <td>{{$userap->email}}</td>
            <td>{{$userap->created_at}}</td>
            <td>{{$userap->loginapproval}}</td>
          </tr>
        </tbody>
      </table>
      @endforeach
    </div>
  </div>
</div>
</div>

</div>
@endsection

我在未批准的表格中添加了一个按钮。我想点击它将批准值从true更改为false。

1 个答案:

答案 0 :(得分:0)

要继续在轨道上,您只需要实现approveUser()。但是您需要将唯一标识符(id)传递给函数:

<td><button type="button" data-user-id="{{$user->id}}" class="btn btn-primary j-approve-user" onclick="approveUser()">Approve</button></td>

然后在页面底部添加一些javascript。如果你使用的是JQuery,你可以这样做:

$(".j-approve-user").click(function(){
    var userId = $(this).data('userId');
    $.ajax({url: "/user/approve", type: "POST", success: function(result){
        //show some notification to the user
    }});
});
相关问题