当用户单击批准的按钮时,打开一个模式引导程序。在modal中有一个select选项,它选择一个用户检查器。但它没有保存在数据库中。 我想这与我试图更新同一页面上的条目有关吗?这是我的代码:
点击批准的按钮
必须批准= 1且检查员用户= 4
我的刀片
@extends('Admin.master')
@section('style')
<link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css">
@endsection
@section('content')
<div class="col-md-10">
<div class="panel panel-default">
<div class="panel-heading main-color-bg">
<h3 class="panel-title">List of Requisitions</h3>
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>School Name</th>
<th>Requisition Code</th>
<th>Activity</th>
<th>Telephone</th>
<th>Requisition Type</th>
<th>Requisition Status</th>
<th>Display Details</th>
</tr>
</thead>
<tbody>
@forelse ($requisitions as $requisition)
@forelse($requisition->activities as $activity)
<tr>
<td>{{ $requisition->schools->school_name }}</td>
<td class="translate">{{ $requisition->id }}</td>
<td>{{ $activity->group->group_name }}</td>
<td>{{ $requisition->schools->type }}</td>
<td class="translate">{{ $requisition->schools->phone }}</td>
<td>{{ $requisition->schools->type }}</td>
<td>
<div class="btn-group btn-group-xs">
<a class="btn btn-success btn-xs" data-toggle="modal" data-target="#requisition">Approved</a>
<form class="btn-group" action="{{ route('requisitions.unapproved', ['id' => $requisition->id]) }}" method="post">
{{ method_field('PATCH') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-danger btn-xs">Disapproval</button>
</form>
</div>
</td>
@empty
Please go to back
@endforelse
@empty
Please go to back
@endforelse
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="modal fade" id="requisition" tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<form action="{{ route('requisitions.update', ['id' => $requisition->id]) }}" method="post">
{{ method_field('PATCH') }}
{{ csrf_field() }}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">List of inspection</h4>
</div>
<div class="modal-body">
<select class="form-control" name="inspector_user_id">
@foreach($users as $user)
<option value="{{ $user->id }}">{{ $user->first_name }} {{ $user->last_name }}</option>
@endforeach
</select>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div>
@endsection
@section('script')
<script src="https://unpkg.com/sweetalert2@7.18.0/dist/sweetalert2.all.js"></script>
@endsection
控制器
public function update(Request $request, $requisition)
{
$approved = Requisition::findOrFail($requisition);
$approved->approved = 1;
$approved->inspector_user_id = $request->input('inspector_user_id');
$approved->save();
alert()->success('It done', 'OK')->persistent('OK');
return redirect()->back();
}
public function unapproved(Request $request, $id)
{
$unApproved = Requisition::findOrFail($id);
$unApproved->approved = 0;
$unApproved->save();
alert()->success('It done', 'Cancel')->persistent('OK');
return redirect()->back();
}
我的模特
protected $fillable = [
'status',
'inspector_user_id'
];
web.php
Route::resource('requisitions', 'RequisitionController');