Just to have an example. After I click the button it should move the row into another table in the database just like it is shown here and delete it afterwards. After I click the approve button the data row should transfer to another table in database. I really don't know how to start something like this in Laravel and I really can't find something related.
Here's my view.blade.php
<table class="table table-striped table-bordered tbl_pendingres" id="dataTable" width="100%" cellspacing="0"> <thead> <tr> <th hidden>Id</th> <th>Name</th> <th>Equipment</th> <th>Reservation Date</th> <th>Room</th> <th>Action</th> </tr> </thead> <tbody> @foreach ($app as $resdata) <tr> <td hidden>{{$resdata->id}} </td> <td>{{$resdata->name}} </td> <td>{{$resdata->Name_item}}</td> <td>{{$resdata->dt_item}}</td> <td>{{$resdata->room_item}} </td> <td> <form action="admin.reservations.store{{ $resdata->id}}" method="POST"> {{ csrf_field() }} <button type="submit" class="btn btn-primary btn-sm" >Accept <i class="fas fa-chevron-right"></i></button></a> </form> <button type="button" class="btn btn-danger btn-sm">Cancel <i class="fas fa-times"></i></button> </td> </tr> @endforeach </tbody> </table>
Here's my reservation controller
public function store($id) { $first = Reservation::find($id); //this will select the row with the given id //now save the data in the variables; $ab = $first->name; $cd = $first->Name_item; $ef = $first->dt_item; $gh = $first->room_item; $ij = $first->ldate_item; $second = new AcceptedReservation(); $second->a_name = $ab; $second->a_nitem = $cd; $second->a_ditem = $ef; $second->a_ritem = $gh; $second->a_ldateitem = $ij; $second->save(); //then return to your view or whatever you want to do return view('admin.reservations.index')->with('message','Reservation Accepted'); }
Also when i clicking the button it always having error Too few arguments to function App\Http\Controllers\Admin\ReservationsController::store(), 0 passed in C:\laragon\www\ecmtech\vendor\laravel\framework\src\Illuminate\Routing\Controller.php on line 54 and exactly 1 expected
keep the store function empty remove $id also.like this
public function store()
{
// do nothing
}
Create a new function like this in the controller
public function acceptReservation(Request $request, $id)
{
$first = Reservation::find($id); //this will select the row with the given id
//now save the data in the variables;
$ab = $first->name;
$cd = $first->Name_item;
$ef = $first->dt_item;
$gh = $first->room_item;
$ij = $first->ldate_item;
$second = new AcceptedReservation();
$second->a_name = $ab;
$second->a_nitem = $cd;
$second->a_ditem = $ef;
$second->a_ritem = $gh;
$second->a_ldateitem = $ij;
$second->save();
/// IF YOU NEED TO REMOVE 1st TABLE VALUE
$first->delete();
//then return to your view or whatever you want to do
return redirect()->route('admin.reservations.index')->with('message','Reservation Accepted');
}
now DEFINE The ROUTE Like this
Route::post('reservation-accept/{id}', [ReservationsController::class,'acceptReservation'])->name('reservation.accept');
Now where you are adding the accept button add it call it like this
<form action="{{route('admin.reservation.accept',$resdata->id)}}" method="POST">
@csrf
<button type="submit" class="btn btn-primary btn-sm" >Accept <i class="fas fa-chevron-right"></i></button></a>
</form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.