Commit e15bc28e authored by Julien Ait azzouzene's avatar Julien Ait azzouzene
Browse files

in-progress: make model class for diving groups

parent 75792691
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
<?php

namespace App\Models;

use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class DivingGroup extends Model
{
    protected $table = 'CAR_DIVING_GROUP';

    use HasFactory;

    public function getDivers(){
        $registrations = DivingSignUpModel::where('DS_CODE', $this->DS_CODE)->where('DG_NUMBER', $this->DG_NUMBER)->get();

        $divers = [];

        foreach($registrations as $registration){
            $divers[] = User::find($registration->US_ID);
        }

        return $divers;
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -31,4 +31,8 @@ public function getParticipants(): array{

        return $participants;
    }

    public function getDivingGroups(){
        return DivingGroup::where('DS_CODE', $this->DS_CODE)->get();
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -8,8 +8,7 @@
class DivingSignUpModel extends Model
{
    protected $table = 'car_registration';
    protected $primaryKey = ['us_id', 'ds_code'];
    protected $keyType = ['int', 'string'];
    
    protected $fillable = ['US_ID', 'DS_CODE'];
    use HasFactory;
}
+1 −1
Original line number Diff line number Diff line
@@ -18,4 +18,4 @@
    return false;
}

require_once __DIR__.'/index.php';
require_once __DIR__.'/public/index.php';