你好我试图将一个变量及其值传递给控制器, 我想这样做:所以我有一个请求表,每个请求都有它的按钮,调用模态和模态形式我想将它传递给控制器我的代码,直到现在
包含每个请求的表单作为按钮的第一部分:
<div class="col-md-12">
<form method="POST" action="/borrow">
{{csrf_field()}}
<div class="card mb-3">
<div class="card-header">Kerkesat</div>
<div class="card-body px-0">
<table id="myTable" class="table table-sm table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Libri</th>
<th>Antari</th>
<th>Veprimi</th>
</tr>
</thead>
<tbody>
@foreach($bookRequests as $request)
@if($request->borrow != null)
@else
<tr>
<td>{{$request->book->title}}</td>
<td>{{$request->user->name}}</td>
<td>
<button type="submit" name="btn" value="<?php echo $request->id ?>" onClick="return validate()"><a href="#" onClick="return validate()" class="btn btn-outline-secondary btn-sm" data-toggle="modal" data-target="#AproveRequestModal">Lejo</a></button>
<a href="#" class="btn btn-outline-primary btn-sm">Vepro</a>
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
</div>
</div>
该模式位于主窗体内:
<div class="modal fade" id="AproveRequestModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Aprovo Kerkesen</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="recipient-name" class="form-control-label">Cakto Daten e Kthimit:</label>
<select id="borrow_end" name="borrow_end" class="form-control" required>
<option value="{{$time = Carbon\Carbon::today()->addDay()->toDateString()}}">Pas 1 dite - {{$time}}</option>
<option value="{{$time = Carbon\Carbon::today()->addWeek()->toDateString()}}">Pas 1 jave - {{$time}}</option>
<option value="{{$time = Carbon\Carbon::today()->addWeek(2)->toDateString()}}">Pas 2 jave - {{$time}}</option>
<option value="{{$time = Carbon\Carbon::today()->addMonth()->toDateString()}}">Pas 1 muaji - {{$time}}</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" onclic="confirmSubmit(event)">Save changes</button>
</div>
</div>
</div>
</div>
</form>
控制器:这里我无法访问按钮的值
public function store(Request $request)
{
if(!isset($request->borrow_type)){
$bookRequest = \App\Request::find($request->request_id) ;
$test = $request->input('btn');
dd($test);
$borrow = new Borrow;
$borrow->request_id = $bookRequest->id;
$borrow->borrow_start = Carbon::today();
$borrow->borrow_end = $request->borrow_end;
$borrow->loaned_by = Auth::id();
$borrow->status= 'active';
$borrow->save();
$bookRequest->status = 'expired';
$bookRequest->save();
}
}
当我尝试dd时,它会让所有情况都为null
答案 0 :(得分:0)
将此行放在button
上方,并从按钮中移除value
属性:
<input type="hidden" name="request_id" value="{{ $request->id }}" />