Skip to content

Commit aca5051

Browse files
committed
Ban User and admin panel checkbox styles
1 parent f5c7fef commit aca5051

File tree

6 files changed

+183
-5
lines changed

6 files changed

+183
-5
lines changed

EasyShop/app/Http/Controllers/AdminController.php

+16
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,22 @@ public function submitAlt(Request $request){
237237
return back();
238238
}
239239

240+
public function users(){
241+
242+
$usersData = DB::table('users')
243+
// ->Join('address','address.user_id','users.id')
244+
->get();
245+
return view('admin.users',compact('usersData', $usersData));
246+
}
247+
public function updateRole(Request $request){
248+
$userId =$request->userID;
249+
$role_val = $request->role_val;
250+
251+
$upd_role = DB::table('users')->where('id',$userId)->update(['admin' =>$role_val]);
252+
if($upd_role){
253+
echo "role is updated successfully";
254+
}
255+
}
240256

241257

242258

EasyShop/app/Http/Controllers/Auth/LoginController.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use App\Http\Controllers\Controller;
66
use Illuminate\Foundation\Auth\AuthenticatesUsers;
7-
7+
use Illuminate\Http\Request;
88
class LoginController extends Controller
99
{
1010
/*
@@ -38,4 +38,12 @@ public function __construct()
3838

3939
}
4040

41+
protected function credentials(Request $Request){
42+
$credentials = $Request->only($this->username(),'password'); // getting data from login form
43+
return array_add($credentials, 'isBan',0); // 0 means all fine and can login
44+
}
45+
46+
47+
48+
4149
}

EasyShop/app/User.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ class User extends Authenticatable
2626
protected $hidden = [
2727
'password', 'remember_token',
2828
];
29-
29+
3030
public function isAdmin(){
3131
return $this->admin; // mysql table column
3232
}
33-
33+
3434
public function orders(){
3535
return $this->hasMany(Orders::class);
3636
}
37-
37+
3838
}

EasyShop/resources/views/admin/index.blade.php

+29-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,35 @@
88

99
<section id="main-content">
1010
<section class="wrapper">
11-
11+
<section class="panel">
12+
<div id="c-slide" class="carousel slide auto panel-body">
13+
<ol class="carousel-indicators out">
14+
<li class="" data-slide-to="0" data-target="#c-slide"></li>
15+
<li class="active" data-slide-to="1" data-target="#c-slide"></li>
16+
<li class="" data-slide-to="2" data-target="#c-slide"></li>
17+
</ol>
18+
<div class="carousel-inner">
19+
<div class="item text-center">
20+
<h3>Creative is new model of Admin</h3>
21+
<small class="">Based on Bootstrap 3</small>
22+
</div>
23+
<div class="item text-center active">
24+
<h3>Massive UI Elements</h3>
25+
<small class="">Fully Responsive</small>
26+
</div>
27+
<div class="item text-center">
28+
<h3>Well Documentation</h3>
29+
<small class="">Easy to Use</small>
30+
</div>
31+
</div>
32+
<a data-slide="prev" href="#c-slide" class="left carousel-control">
33+
<i class="arrow_carrot-left_alt2"></i>
34+
</a>
35+
<a data-slide="next" href="#c-slide" class="right carousel-control">
36+
<i class="arrow_carrot-right_alt2"></i>
37+
</a>
38+
</div>
39+
</section>
1240
</section>
1341
</section>
1442

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
@extends('admin.master')
2+
3+
@section('content')
4+
<style>
5+
<?php for($i=1;$i<15;$i++){?>
6+
#banUser<?php echo $i ;?>{ display:none}
7+
.banUserDiv<?php echo $i ;?> {
8+
width: 120px; height: 40px; background: #333; border-radius: 50px; position: relative;
9+
}
10+
.banUserDiv<?php echo $i ;?>:before {
11+
content: 'Yes'; position: absolute; top: 12px; left: 13px; height: 2px; color: #26ca28; font-size: 16px;
12+
}
13+
.banUserDiv<?php echo $i ;?>:after {
14+
content: 'No'; position: absolute; top: 12px; left: 84px; height: 2px; color: #fff; font-size: 16px;
15+
}
16+
17+
.banUserDiv<?php echo $i ;?> label {
18+
display: block; width: 52px; height: 22px; border-radius: 50px; transition: all .5s ease;
19+
cursor: pointer; position: absolute; top: 9px; z-index: 1; left: 12px; background: #ddd;
20+
}
21+
.banUserDiv<?php echo $i ;?> input[type=checkbox]:checked + label {
22+
left: 60px; background: #26ca28;
23+
}
24+
<?php }?>
25+
</style>
26+
27+
<script>
28+
$(document).ready(function(){
29+
<?php for($i=1;$i<15;$i++){?>
30+
$('#successMsg<?php echo $i;?>').hide();
31+
$('#role<?php echo $i;?>').change(function(){
32+
var role_val<?php echo $i;?> = $('#role<?php echo $i;?>').val();
33+
var userId<?php echo $i;?> = $('#userId<?php echo $i;?>').val();
34+
$.ajax({
35+
type: 'get',
36+
data: 'userID='+userId<?php echo $i;?> + '&role_val=' + role_val<?php echo $i;?>,
37+
url: '<?php echo url('/admin/updateRole');?>',
38+
success: function(response){
39+
console.log(response);
40+
$('#successMsg<?php echo $i;?>').show();
41+
$('#successMsg<?php echo $i;?>').html(response);
42+
}
43+
});
44+
});
45+
$('#banUser<?php echo $i;?>').click(function(){
46+
//alert('yes');
47+
if(document.getElementById('banUser<?php echo $i;?>').checked){
48+
alert('checked');
49+
}else{
50+
alert('uncheck');
51+
}
52+
});
53+
<?php }?>
54+
});
55+
</script>
56+
<section id="container" class="">
57+
@include('admin.sidebar')
58+
<section id="main-content">
59+
<section class="wrapper">
60+
<div class="content-box-large">
61+
<h1>Users</h1>
62+
<table class="table table-striped table-advance table-hover">
63+
<thead>
64+
<tr>
65+
<th><i class="icon_profile"></i> Name</th>
66+
<th><i class="icon_mail_alt"></i> Email</th>
67+
<th><i class="icon_calendar"></i> Role</th>
68+
<th><i class="icon_mobile"></i> Ban</th>
69+
<th><i class="icon_cogs"></i> Actions</th>
70+
</tr>
71+
</thead>
72+
73+
74+
<tbody>
75+
<?php $countRole =1;?>
76+
@foreach($usersData as $userData)
77+
<input type="hidden" value="{{$userData->id}}" id="userId<?php echo $countRole;?>">
78+
79+
<tr>
80+
<td>{{$userData->name}}</td>
81+
<td>{{$userData->email}}</td>
82+
<td><select name="role" class="form-control" id="role<?php echo $countRole;?>">
83+
<option value="1" @if($userData->admin=='1')
84+
selected="selected" @endif>admin</option>
85+
<option value="0" @if($userData->admin=='' || $userData->admin=='0')
86+
selected="selected" @endif>user</<option>
87+
</select>
88+
<p id="successMsg<?php echo $countRole;?>"
89+
class="alert alert-success"></p>
90+
</td>
91+
<td>
92+
<div class="banUserDiv<?php echo $countRole;?>">
93+
<input type="checkbox" id="banUser<?php echo $countRole;?>"/>
94+
<label for="banUser<?php echo $countRole;?>"></label>
95+
</div>
96+
</td>
97+
<td>
98+
<div class="btn-group">
99+
<a class="btn btn-info popovers" data-trigger="hover"
100+
data-content="Edit user" data-placement="top" href="#">
101+
<i class="icon_minus_alt2"></i>
102+
</a>
103+
<a class="btn btn-danger popovers" data-trigger="hover"
104+
data-content="Remove" data-placement="top" href="#">
105+
<i class="icon_close_alt2"></i>
106+
</a>
107+
</div>
108+
</td>
109+
</tr>
110+
<?php $countRole++;?>
111+
@endforeach
112+
113+
</tbody>
114+
</table>
115+
116+
</div>
117+
</section>
118+
</section>
119+
120+
121+
@endsection

EasyShop/routes/web.php

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
34
Route::get('/', 'HomeController@index');
45
Route::get('/home', 'HomeController@index');
56

@@ -86,6 +87,10 @@
8687

8788
Route::get('addAlt/{id}', 'AdminController@addAlt');
8889
Route::post('submitAlt','AdminController@submitAlt');
90+
Route::get('/users','AdminController@users');
91+
Route::get('/updateRole','AdminController@updateRole');
92+
93+
8994
});
9095
Route::get('/logout', 'Auth\LoginController@logout');
9196
Route::post('addToWishList', 'HomeController@wishList');

0 commit comments

Comments
 (0)