I want to give function to both approve and decline button that is in admin dashboard and display the result as remarks:pending/accepted/decline in user's dashboard.
here is my admin view
dashboard.php.blade
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th hidden>Id</th>
<th>Name</th>
<th>Equipment</th>
<th>Reservation Date</th>
<th>Rooms</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach ($res as $resdata)
<tr>
<td hidden> </td>
<td>{{$resdata->name}} </td>
<td>{{$resdata->Name_item}}</td>
<td>{{$resdata->dt_item}}</td>
<td>{{$resdata->room_item}} </td>
<td>
<button type="button" class="btn btn-primary btn-sm" >Accept <i class="fas fa-chevron-right"></i></button></a>
<button type="button" class="btn btn-danger btn-sm">Decline <i class="fas fa-times"></i></button>
</td>
</tr>
@endforeach
</tbody>
</table>
My Answer:
To achieve this functionality, you can add a route and controller method in your Laravel application to handle the approval and rejection actions. Here's an example of how you can do this:
1. Define routes in your web.php file:
php
Route::post('/approve-reservation/{id}', 'ReservationController@approve')->name('approve.reservation');
Route::post('/reject-reservation/{id}', 'ReservationController@reject')->name('reject.reservation');
2. Create a ReservationController with the `approve` and `reject` methods:
php
namespace App\Http\Controllers;
use App\Models\Reservation;
use Illuminate\Http\Request;
class ReservationController extends Controller
{
public function approve($id)
{
$reservation = Reservation::find($id);
$reservation->status = 'accepted';
$reservation->save();
return redirect()->back()->with('success', 'Reservation approved successfully.');
}
public function reject($id)
{
$reservation = Reservation::find($id);
$reservation->status = 'declined';
$reservation->save();
return redirect()->back()->with('success', 'Reservation declined successfully.');
}
}
3. Update your dashboard.php.blade view to include form submissions for the approve and reject buttons:
html
@foreach ($res as $resdata)
{{$resdata->name}}
{{$resdata->Name_item}}
{{$resdata->dt_item}}
{{$resdata->room_item}}
@endforeach
4. Update your Reservation model to include the `status` attribute:
php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Reservation extends Model
{
protected $fillable = ['name', 'Name_item', 'dt_item', 'room_item', 'status'];
}
With these changes, when the admin clicks on the Accept or Decline button, the status of the reservation will be updated in the database. You can then display the status in the user's dashboard based on the `status` attribute of the reservation.
© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog | Privacy Policy | Terms & Conditions | Contact Us
Create blog | Privacy Policy | Terms & Conditions | Contact Us
Rate this post
5 of 5 based on 6545 votesComments