Commit 510710e6 authored by Julien Ait azzouzene's avatar Julien Ait azzouzene
Browse files

feat: show participants of a diving session (no style)

parent 156d07ee
Loading
Loading
Loading
Loading
+16 −5
Original line number Diff line number Diff line
@@ -5,16 +5,27 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

use Illuminate\Support\Facades\DB;

class DivingSession extends Model
{
    protected $table = 'car_diving_session';
    protected $primaryKey = 'ds_code';
    protected $primaryKey = 'DS_CODE';
    protected $keyType = 'string';
    public $timestamps = false;

    /*protected $attributes = [
        'DS_CODE' => 'test'
    ];*/

    use HasFactory;

    public function getParticipants(): array{
        $registrations = DB::table('CAR_REGISTRATION')->where('DS_CODE', $this->DS_CODE)->get();
        $participants = [];

        foreach($registrations as $registration){
            if($registration->REG_ACTIVE === 1){
                $participants[] = User::find($registration->US_ID);
            }
        }

        return $participants;
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -41,4 +41,10 @@ class User extends Authenticatable
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    protected $table = 'car_user';

    protected $primaryKey = 'US_ID';

    protected $keyType = 'int';
}
+3 −0
Original line number Diff line number Diff line
@foreach($users as $user)   
<p>{{$user->US_NAME}} {{$user->US_FIRST_NAME}}</p>
@endforeach
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
<?php

use App\Models\DivingSession;
use Illuminate\Support\Facades\Route;

/*
@@ -16,3 +17,10 @@
Route::get('/', function () {
    return view('welcome');
});

Route::get('/plongees/{id}', function($id){
    $divingSession = DivingSession::find($id);
    return view('divingSessions.showParticipants',[
        'users' => $divingSession->getParticipants()
    ]);
});