You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.0 KiB
54 lines
2.0 KiB
<?php
|
|
|
|
namespace App\Domains\Academic\Providers;
|
|
|
|
use App\Domains\Academic\Models\StudyProgram;
|
|
use App\Domains\Academic\Models\Term;
|
|
use App\Domains\Admission\Models\AdmissionSchedule;
|
|
use App\Domains\Admission\Models\FeeRate;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class RelationshipServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Boot cross-domain runtime relationships.
|
|
*
|
|
* This provider is strictly dedicated to runtime, decoupled cross-domain
|
|
* relationship definitions. Use Model::resolveRelationUsing() here to wire
|
|
* explicit polymorphic or foreign-key macros between models that live in
|
|
* different domains — without introducing a hard compile-time dependency
|
|
* between those domains.
|
|
*
|
|
* Do NOT add route registrations, bindings, event listeners, or any other
|
|
* bootstrapping logic here. Keep this file focused on relationships only.
|
|
*
|
|
* Example:
|
|
*
|
|
* Order::resolveRelationUsing('customer', fn (Order $order) =>
|
|
* $order->belongsTo(Customer::class, 'customer_id')
|
|
* );
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
// Register cross-domain relationships below.
|
|
AdmissionSchedule::resolveRelationUsing('term', fn (AdmissionSchedule $admissionSchedule) => $admissionSchedule->belongsTo(
|
|
related: Term::class,
|
|
foreignKey: 'term_id'
|
|
));
|
|
Term::resolveRelationUsing('admission_schedules', fn (Term $term) => $term->hasMany(
|
|
related: AdmissionSchedule::class,
|
|
foreignKey: 'term_id',
|
|
localKey: 'id'
|
|
));
|
|
|
|
FeeRate::resolveRelationUsing('study_program', fn (FeeRate $programTrack) => $programTrack->belongsTo(
|
|
related: StudyProgram::class,
|
|
foreignKey: 'study_program_id'
|
|
));
|
|
StudyProgram::resolveRelationUsing('fee_rates', fn (StudyProgram $studyProgram) => $studyProgram->hasMany(
|
|
related: FeeRate::class,
|
|
foreignKey: 'study_program_id',
|
|
localKey: 'id'
|
|
));
|
|
}
|
|
}
|
|
|