Perform specific action on button in Bootstrap modal (Laravel)
I created a modal which displays information specific to their id entries and placed the Approve and Reject button as below.
When a user click on “Accept” or “Reject”, it needs to pass id related to the viewed entries so the user can perform the requested action, whether to accept or reject the entries.
vendor.blade.php
<div class="modal-footer">
<span class="pull-left">
<form method="POST" action="">
@method('PUT')
@csrf
<button type="submit" class="btn btn-success">Approve</button>
</form>
</span>
<span class="pull-right">
<form method="POST" action="">
@method('PUT')
@csrf
<button type="submit" class="btn btn-danger">Reject</button>
</form>
</span>
</div>
ApprovedVendorController.php
<?php
namespace AppHttpControllers;
use AppUser;
use AppVendor;
use IlluminateHttpRequest;
use IlluminateSupportFacadesDB;
class ApproveVendorController extends Controller
{
public function approve(Request $request, $id)
{
DB::insert('insert into mides_users(name, email, password) select name,roc_no,password from mides_vendors where id = :id', ['id' => $id]);
DB::update('update mides_vendors set status = :status where id = :id', ['status' => 'Approved', 'id' => $id]);
return redirect('/');
}
public function reject(Request $request, $id)
{
DB::update('update mides_vendors set status = :status where id = :id', ['status' => 'Rejected', 'id' => $id]);
return redirect('/');
}
}
routes/web.php
Route::prefix('/panel')->group(function () {
Route::get('/dashboard', function () {
return view('panel.dashboard');
});
Route::get('/approve-vendor', 'VendorController@showNewRegistration');
Route::get('/vendor-approved', 'VendorController@showApproved');
Route::get('/vendor-reject', 'VendorController@showRejected');
Route::put('/approve', 'ApproveVendorController@approve')->name('approve');
Route::put('/reject', 'ApproveVendorController@reject')->name('reject');
});
However, it returns this error.
Error got after clicking Accept or Reject
How do I pass the id of data? I tried as shown in pass the database value to modal popup to create the modal using second answer option (besides the ajax ones). Do I need to create another controller for these?
from Laravel Questions and Answers https://laravelquestions.com/php/perform-specific-action-on-button-in-bootstrap-modal-laravel/
via Lzo Media
No comments:
Post a Comment