我正在开发一个管理面板,显示驱动程序列表'我有一个选择列表,并选择“批准”,“拒绝”。当管理员点击批准数据库字段值变为'1'并且同样如单击“拒绝”数据库字段将更改为“0”。 我有代码在点击时更改db值,
public function postApprove($id)
{
$application = Move::where('id', '=', e($id))->first();
if($application)
{
$application->approved =1;
$application->save();
}
}
和下降一样,
public function postdecline($id)
{
$application = Move::where('id', '=', e($id))->first();
if($application)
{
$application->approved =0;
$application->save();
}
}
现在我正在使用两个单独的按钮。但是我如何通过选择框列表实现这一点,任何人都可以帮助
我希望点击列表项的操作不在提交上。点击任何操作,例如“批准”,“拒绝”,“验证”特定操作 ld为特定用户制作。
我在这里查看代码,
@extends('layouts.blank')
@section('main_container')
<div class="main-content">
<!-- page content -->
<div id="page-wrapper">
<div class="graphs">
<h3 class="blank1">Drivers List</h3>
@if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{ $message }}</p>
</div>
@endif
<div class="xs tabls">
<div class="bs-example4" data-example-id="contextual- table">
<table class="table table-bordered">
<thead>
<tr>
<th>Driver name</th>
<th>Email</th>
<th>Phone</th>
<th>Total Bookings</th>
<th>Completed bookings</th>
<th>Cancelled bookings</th>
<th>Action</th>
</tr>
</thead>
@foreach( $users as $user )
<tbody>
<tr class="active">
<td>{{$user->id}}</td>
<td>{{$user->name}}</td>
<td>{{$user->email}}</td>
<td>{{''}}</td>
<td>{{''}}</td>
<td>{{''}}</td>
<td>
<select class="form-control" >
<option value=""></option>
<option value=""><a href="{{route('toggleApprove',
['id'=>$user->id,'isApproved'=>1])}>Approve
</a></option>
<option><a href="{{route('toggleApprove',
['id'=>$user->id,'isApproved'=>0])}}"> Deny </a> </option>
</select>
</td>
</tr>
@endforeach
@endsection
答案 0 :(得分:2)
使用find
和update
,
对于选择框,您需要通过表单获取值
路线:
Route:post('post/{id}','Post@toggleApprove')->name('toggleApprove');
控制器:
public function toggleApprove(Request $request,$id) {
Move::find($id)->update([approved => $request->approved]);
}
视图:
<form action="{{route('toggleApprove')}}" method="POST">
{{csrf_token()}}
<select name="approve">
<option value="1">Approve</option>
<option value="0">Deny</option>
</select>
<input type="submit">
</form>
答案 1 :(得分:0)
Route:
Route::get('/approve-user/{id}', 'AdminController@approve_user')->name('admin.approve.user');
Your view page like this:
<div class="dropdown">
<button class="btn btn-flat btn-info dropdown-toggle" type="button" id="dropdownMenu1" name="action" data-toggle="dropdown">
Actions
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
@if($application->status == 1)
<li role="presentation"><a role="menuitem" tabindex="-1" href="{{ route('admin.approve.user',$application->id) }}">UnApprove</a></li>
@else
<li role="presentation"><a role="menuitem" tabindex="-1" href="{{ route('admin.approve.user',$application->id) }}">Approve</a></li>
@endif
<li role="presentation"><a role="menuitem" tabindex="-1" href="">Edit Details</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="">View History</a></li>
</ul>
</div>
您的控制器页面如下:
public function approve_user()
{
$id = \Request::segment(3);
$application = User::find($id);
if ($application->approved == 1)
{
$application->approved = 0;
$msg = 'User UnApproved successfully';
}
else {
$application->approved = 1;
$msg = 'User Approved successfully';
}
$application->save();
return Redirect::back()->with('message',$msg);
}