1. Go to this page and download the library: Download andydefer/laravel-mixins library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use AndyDefer\Mixins\Traits\HasAvailabilityAttributes;
use Illuminate\Database\Eloquent\Model;
final class Doctor extends Model
{
use HasAvailabilityAttributes;
// Surchargez cette méthode pour ajouter des conditions personnalisées
protected function isSchedulable(): bool
{
return $this->is_active && $this->user_type->isDoctor();
}
}
$doctor = Doctor::find(1);
// Vérifier la disponibilité immédiate
if ($doctor->is_available_now) {
echo "Le médecin est disponible maintenant";
}
// Récupérer le prochain créneau
$nextSlot = $doctor->next_slot;
if ($nextSlot) {
$start = $nextSlot->getStart()->toDateTimeString();
$end = $nextSlot->getEnd()->toDateTimeString();
echo "Prochain créneau : $start - $end";
}
// Vérifier les disponibilités du jour
if ($doctor->has_availability_on_date) {
$minutes = $doctor->total_available_minutes;
echo "Disponible aujourd'hui : $minutes minutes";
}
use AndyDefer\Mixins\Traits\HasRatingAttributes;
use Illuminate\Database\Eloquent\Model;
final class Product extends Model
{
use HasRatingAttributes;
// Surchargez cette méthode pour ajouter des conditions personnalisées
protected function isRateable(): bool
{
return $this->is_active && $this->status === 'published';
}
}
if ($product->has_ratings) {
// Afficher les évaluations
}
declare(strict_types=1);
namespace App\Models;
use AndyDefer\Mixins\Traits\HasAvailabilityAttributes;
use AndyDefer\Mixins\Traits\HasRatingAttributes;
use Illuminate\Database\Eloquent\Model;
final class Doctor extends Model
{
use HasAvailabilityAttributes;
use HasRatingAttributes;
protected $fillable = [
'name',
'email',
'is_active',
'user_type',
];
protected function isSchedulable(): bool
{
return $this->is_active && $this->user_type === 'doctor';
}
protected function isRateable(): bool
{
return $this->is_active && $this->user_type === 'doctor';
}
}
declare(strict_types=1);
namespace App\Http\Controllers\Api;
use App\Models\Doctor;
use Illuminate\Http\JsonResponse;
final class DoctorController
{
public function show(Doctor $doctor): JsonResponse
{
return response()->json([
'id' => $doctor->id,
'name' => $doctor->name,
'email' => $doctor->email,
'available_now' => $doctor->is_available_now,
'next_slot' => $doctor->next_slot,
'has_availability_today' => $doctor->has_availability_on_date,
'available_minutes' => $doctor->total_available_minutes,
'average_rating' => $doctor->average_rating,
'rating_count' => $doctor->rating_count,
'rating_distribution' => $doctor->rating_distribution,
'has_ratings' => $doctor->has_ratings,
]);
}
}