如何在被卡住的Laravel代码中定义transaction_id或初始化transaction_id。
这是AdminContoller.php上的代码
public function provetransaction(Request $req, $transaction_id)
{
$transaction_id = transaction::find ($req->transaction_id);
$provetransaction = \DB::table('transaction')->where('transaction_id', $transaction_id)->first();
return view('provetransaction', compact('amount_paid', 'transaction_id'));
}
public function updateprove(Request $request, $transaction_id)
{
switch($request->get('approve'))
{
case 0:
Post::postpone($transaction_id);
break;
case 1:
Post::approve($transaction_id);
break;
case 2:
Post::reject($transaction_id);
break;
case 3:
Post::postpone($transaction_id);
break;
default:
break;
}
return redirect('view_all_transaction');
}
下面是我的web.php,我在其中定义了路线。我已更新,我删除了ID,而改用了transaction_id。
web.php
Route::get('/view_all_transaction', 'AdminController@view_all_transaction')->name('admin');
Route::post('/view_all_transaction/{transaction_id}', 'AdminController@provetransaction')->name('admin');
Route::post('/view_all_transaction', 'AdminController@updateprove')->name('admin');
这是我的view_all_transaction.blade.php传递操作的位置 所以我错了。
<td><a href="{{ action('AdminController@provetransaction', $view_all_transaction->transaction_id) }}" class="btn btn-warning">Moderate</a></td>
<div id="MyModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<!-- Modal Content: begins -->
<div class="modal-content">
<!-- Modal Header -->
<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" id="gridSystemModalLabel">Your Headings</h4>
</div>
<!-- Modal Body -->
<div class="modal-body">
<div class="body-message">
<h4>Approve </h4>
<div class="container">
<form method="post" action="action="{{action('AdminController@updateprove', $transaction_id)}}">
@csrf
<div class="row">
<div class="col-md-4"></div>
<div class="form-group col-md-4">
<lable>Approval</lable>
<select name="approve">
<option value="0" @if($view_all_transaction->status==0)selected @endif>Pending</option>
<option value="1" @if($view_all_transaction->status==1)selected @endif>Approve</option>
<option value="2" @if($view_all_transaction->status==2)selected @endif>Reject</option>
<option value="3" @if($view_all_transaction->status==3)selected @endif>Postponed</option>
</select>
</div>
</div>
<!-- <div class="row">
<div class="col-md-4"></div>
<div class="form-group col-md-4">
<button type="submit" class="btn btn-success" style="margin-top:40px">Update</button>
</div>
</div> -->
</form>
</div>
</div>
</div>
<!-- Modal Footer -->
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button id="btnPrint" type="button" class="btn btn-default">Approve</button>
</div>
</div>
<!-- Modal Content: ends -->
答案 0 :(得分:0)
该错误表明您在视图代码中使用了$ id。为此,您应该在视图中压缩一个名为“ id”的变量。
答案 1 :(得分:0)
尝试
dd($req->all());
并确保请求中包含什么键