I have 3 Database tables: Users, Schedule of Reviews and Appointments.
The users can reserve many schedules, and schedules can be reserved by many users, so basically, the Appointments table is my associative entity to connect the Users and Schedule of Reviews tables
In my installed Laravel Voyager, the Appointments table has a column status to be marked as Paid / Not yet Paid
Now, Whenever the Admin changes the status to PAID, I want the slots column from the Schedule of Appointments table to be decremented or decreased by 1 to literally mark that the user has successfully paid his/her slot for the schedule of review
May I know how or where can I add such code so when Laravel Voyager updates the Appointments table, I can also update the Schedule of Reviews table?
Thank you very much!
The typical way to achieve this particular scenario is by overriding model, you can implement logic in your Model, which I am assuming App\ScheduleAppointments:
namespace App;
use Illuminate\Database\Eloquent\Model;
class ScheduleAppointments extends Model
{
//Your model logic
//
//
//
//
/**
* OVERRIDE Boot Method
*/
protected static function boot()
{
parent::boot();
static::updating(function ($appointment) {
if($appointment->status == 'PAID'){
$appointment->slot -=1;
}
});
}
}