using cloude sonet 3.5 i have used the prompt to create the migrations and their files and installed api package

This commit is contained in:
ghassan committed 2026-01-20 10:06:01 +03:00
1 parent f27b5abf02
commit 4a7353e3fc
23 files changed
+1871 -2

No files matched your search

+168
View File
@@ -0,0 +1,168 @@
<?php
namespace App\Http\Controllers;
use App\Models\User;
use App\Models\UserRelationship;
use App\Services\FamilyService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class FamilyController extends Controller
{
protected $familyService;
public function __construct(FamilyService $familyService)
{
$this->familyService = $familyService;
}
/**
* Display the family dashboard.
*
* @return \Illuminate\View\View
*/
public function dashboard()
{
$user = Auth::user();
$dependents = UserRelationship::where('guardian_user_id', $user->id)
->with('dependent')
->get();
$familyInvoices = $this->familyService->getFamilyInvoices($user->id);
return view('family.dashboard', compact('user', 'dependents', 'familyInvoices'));
}
/**
* Show the form for creating a new family member.
*
* @return \Illuminate\View\View
*/
public function create()
{
return view('family.create');
}
/**
* Store a newly created family member in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(Request $request)
{
$validated = $request->validate([
'full_name' => 'required|string|max:255',
'email' => 'nullable|email|max:255',
'gender' => 'required|in:male,female',
'birthdate' => 'required|date',
'blood_type' => 'nullable|string|max:10',
'nationality' => 'required|string|max:100',
'relationship_type' => 'required|string|max:50',
'is_billing_contact' => 'boolean',
]);
$guardian = Auth::user();
$dependent = $this->familyService->createDependent($guardian, $validated);
return redirect()->route('family.dashboard')
->with('success', 'Family member added successfully.');
}
/**
* Display the specified family member.
*
* @param int $id
* @return \Illuminate\View\View
*/
public function show($id)
{
$user = Auth::user();
$relationship = UserRelationship::where('guardian_user_id', $user->id)
->where('dependent_user_id', $id)
->with('dependent')
->firstOrFail();
return view('family.show', compact('relationship'));
}
/**
* Show the form for editing the specified family member.
*
* @param int $id
* @return \Illuminate\View\View
*/
public function edit($id)
{
$user = Auth::user();
$relationship = UserRelationship::where('guardian_user_id', $user->id)
->where('dependent_user_id', $id)
->with('dependent')
->firstOrFail();
return view('family.edit', compact('relationship'));
}
/**
* Update the specified family member in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\RedirectResponse
*/
public function update(Request $request, $id)
{
$validated = $request->validate([
'full_name' => 'required|string|max:255',
'email' => 'nullable|email|max:255',
'gender' => 'required|in:male,female',
'birthdate' => 'required|date',
'blood_type' => 'nullable|string|max:10',
'nationality' => 'required|string|max:100',
'relationship_type' => 'required|string|max:50',
'is_billing_contact' => 'boolean',
]);
$user = Auth::user();
$relationship = UserRelationship::where('guardian_user_id', $user->id)
->where('dependent_user_id', $id)
->firstOrFail();
$dependent = User::findOrFail($id);
$dependent->update([
'full_name' => $validated['full_name'],
'email' => $validated['email'],
'gender' => $validated['gender'],
'birthdate' => $validated['birthdate'],
'blood_type' => $validated['blood_type'],
'nationality' => $validated['nationality'],
]);
$relationship->update([
'relationship_type' => $validated['relationship_type'],
'is_billing_contact' => $validated['is_billing_contact'] ?? false,
]);
return redirect()->route('family.dashboard')
->with('success', 'Family member updated successfully.');
}
/**
* Remove the specified family member from storage.
*
* @param int $id
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy($id)
{
$user = Auth::user();
$relationship = UserRelationship::where('guardian_user_id', $user->id)
->where('dependent_user_id', $id)
->firstOrFail();
$relationship->delete();
return redirect()->route('family.dashboard')
->with('success', 'Family member removed successfully.');
}
}
@@ -0,0 +1,92 @@
<?php
namespace App\Http\Controllers;
use App\Models\Invoice;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class InvoiceController extends Controller
{
public function __construct()
{
// Auth middleware will be applied in routes
}
/**
* Display a listing of the invoices.
*
* @return \Illuminate\View\View
*/
public function index()
{
$user = Auth::user();
$invoices = Invoice::where('payer_user_id', $user->id)
->with(['student', 'tenant'])
->get();
return view('invoices.index', compact('invoices'));
}
/**
* Display the specified invoice.
*
* @param int $id
* @return \Illuminate\View\View
*/
public function show($id)
{
$user = Auth::user();
$invoice = Invoice::where('id', $id)
->where('payer_user_id', $user->id)
->with(['student', 'tenant'])
->firstOrFail();
return view('invoices.show', compact('invoice'));
}
/**
* Process payment for the specified invoice.
*
* @param int $id
* @return \Illuminate\Http\RedirectResponse
*/
public function pay($id)
{
$user = Auth::user();
$invoice = Invoice::where('id', $id)
->where('payer_user_id', $user->id)
->firstOrFail();
// In a real application, this would integrate with a payment gateway
$invoice->update([
'status' => 'paid'
]);
return redirect()->route('invoices.show', $invoice->id)
->with('success', 'Payment processed successfully.');
}
/**
* Process payment for all unpaid invoices.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function payAll()
{
$user = Auth::user();
$invoices = Invoice::where('payer_user_id', $user->id)
->where('status', '!=', 'paid')
->get();
// In a real application, this would integrate with a payment gateway
foreach ($invoices as $invoice) {
$invoice->update([
'status' => 'paid'
]);
}
return redirect()->route('invoices.index')
->with('success', 'All payments processed successfully.');
}
}
+60
View File
@@ -0,0 +1,60 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Invoice extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'tenant_id',
'amount',
'status',
'due_date',
'student_user_id',
'payer_user_id',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'amount' => 'decimal:2',
'due_date' => 'date',
];
/**
* Get the tenant that owns the invoice.
*/
public function tenant(): BelongsTo
{
return $this->belongsTo(Tenant::class);
}
/**
* Get the student user that owns the invoice.
*/
public function student(): BelongsTo
{
return $this->belongsTo(User::class, 'student_user_id');
}
/**
* Get the payer user that owns the invoice.
*/
public function payer(): BelongsTo
{
return $this->belongsTo(User::class, 'payer_user_id');
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Membership extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'tenant_id',
'user_id',
'status',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'status' => 'string',
];
/**
* Get the tenant that owns the membership.
*/
public function tenant(): BelongsTo
{
return $this->belongsTo(Tenant::class);
}
/**
* Get the user that owns the membership.
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}
+64
View File
@@ -0,0 +1,64 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Tenant extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'owner_user_id',
'club_name',
'slug',
'logo',
'gps_lat',
'gps_long',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'gps_lat' => 'decimal:7',
'gps_long' => 'decimal:7',
];
/**
* Get the owner user that owns the tenant.
*/
public function owner(): BelongsTo
{
return $this->belongsTo(User::class, 'owner_user_id');
}
/**
* Get the members for the tenant.
*/
public function members(): BelongsToMany
{
return $this->belongsToMany(User::class, 'memberships')
->withPivot('status')
->withTimestamps();
}
/**
* Get the invoices for the tenant.
*/
public function invoices(): HasMany
{
return $this->hasMany(Invoice::class);
}
}
+153 -1
View File
@@ -6,6 +6,10 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Carbon\Carbon;
class User extends Authenticatable
{
@@ -18,9 +22,17 @@ class User extends Authenticatable
* @var list<string>
*/
protected $fillable = [
'name',
'full_name',
'email',
'mobile',
'password',
'gender',
'birthdate',
'blood_type',
'nationality',
'addresses',
'social_links',
'media_gallery',
];
/**
@@ -43,6 +55,146 @@ class User extends Authenticatable
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'birthdate' => 'date',
'addresses' => 'array',
'social_links' => 'array',
'media_gallery' => 'array',
];
}
/**
* Get the user's age based on birthdate.
*/
protected function age(): Attribute
{
return Attribute::make(
get: function () {
if (!$this->birthdate) {
return null;
}
return Carbon::parse($this->birthdate)->age;
}
);
}
/**
* Get the user's horoscope based on birthdate.
*/
protected function horoscope(): Attribute
{
return Attribute::make(
get: function () {
if (!$this->birthdate) {
return null;
}
$month = $this->birthdate->month;
$day = $this->birthdate->day;
if (($month == 3 && $day >= 21) || ($month == 4 && $day <= 19)) {
return 'Aries';
} elseif (($month == 4 && $day >= 20) || ($month == 5 && $day <= 20)) {
return 'Taurus';
} elseif (($month == 5 && $day >= 21) || ($month == 6 && $day <= 20)) {
return 'Gemini';
} elseif (($month == 6 && $day >= 21) || ($month == 7 && $day <= 22)) {
return 'Cancer';
} elseif (($month == 7 && $day >= 23) || ($month == 8 && $day <= 22)) {
return 'Leo';
} elseif (($month == 8 && $day >= 23) || ($month == 9 && $day <= 22)) {
return 'Virgo';
} elseif (($month == 9 && $day >= 23) || ($month == 10 && $day <= 22)) {
return 'Libra';
} elseif (($month == 10 && $day >= 23) || ($month == 11 && $day <= 21)) {
return 'Scorpio';
} elseif (($month == 11 && $day >= 22) || ($month == 12 && $day <= 21)) {
return 'Sagittarius';
} elseif (($month == 12 && $day >= 22) || ($month == 1 && $day <= 19)) {
return 'Capricorn';
} elseif (($month == 1 && $day >= 20) || ($month == 2 && $day <= 18)) {
return 'Aquarius';
} else {
return 'Pisces';
}
}
);
}
/**
* Get the user's life stage based on age.
*/
protected function lifeStage(): Attribute
{
return Attribute::make(
get: function () {
if (!$this->birthdate) {
return null;
}
$age = Carbon::parse($this->birthdate)->age;
if ($age >= 0 && $age <= 3) {
return 'Toddler';
} elseif ($age >= 4 && $age <= 12) {
return 'Child';
} elseif ($age >= 13 && $age <= 19) {
return 'Teenager';
} elseif ($age >= 20 && $age <= 59) {
return 'Adult';
} else {
return 'Senior';
}
}
);
}
/**
* Get the dependents for the user.
*/
public function dependents(): HasMany
{
return $this->hasMany(UserRelationship::class, 'guardian_user_id');
}
/**
* Get the guardians for the user.
*/
public function guardians(): HasMany
{
return $this->hasMany(UserRelationship::class, 'dependent_user_id');
}
/**
* Get the clubs owned by the user.
*/
public function ownedClubs(): HasMany
{
return $this->hasMany(Tenant::class, 'owner_user_id');
}
/**
* Get the clubs the user is a member of.
*/
public function memberClubs(): BelongsToMany
{
return $this->belongsToMany(Tenant::class, 'memberships')
->withPivot('status')
->withTimestamps();
}
/**
* Get the invoices where the user is the student.
*/
public function studentInvoices(): HasMany
{
return $this->hasMany(Invoice::class, 'student_user_id');
}
/**
* Get the invoices where the user is the payer.
*/
public function payerInvoices(): HasMany
{
return $this->hasMany(Invoice::class, 'payer_user_id');
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class UserRelationship extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'guardian_user_id',
'dependent_user_id',
'relationship_type',
'is_billing_contact',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'is_billing_contact' => 'boolean',
];
/**
* Get the guardian user that owns the relationship.
*/
public function guardian(): BelongsTo
{
return $this->belongsTo(User::class, 'guardian_user_id');
}
/**
* Get the dependent user that belongs to the relationship.
*/
public function dependent(): BelongsTo
{
return $this->belongsTo(User::class, 'dependent_user_id');
}
}
+58
View File
@@ -0,0 +1,58 @@
<?php
namespace App\Services;
use App\Models\User;
use App\Models\UserRelationship;
use App\Models\Invoice;
class FamilyService
{
/**
* Create a new dependent user and link it to the guardian.
*
* @param User $guardian The guardian user
* @param array $data The dependent user data
* @return User The newly created dependent user
*/
public function createDependent(User $guardian, array $data): User
{
// Create the dependent user
$dependent = User::create([
'full_name' => $data['full_name'],
'email' => $data['email'] ?? null,
'password' => $data['password'] ?? null,
'mobile' => $data['mobile'] ?? null,
'gender' => $data['gender'],
'birthdate' => $data['birthdate'],
'blood_type' => $data['blood_type'] ?? null,
'nationality' => $data['nationality'],
'addresses' => $data['addresses'] ?? [],
'social_links' => $data['social_links'] ?? [],
'media_gallery' => $data['media_gallery'] ?? [],
]);
// Create the relationship between guardian and dependent
UserRelationship::create([
'guardian_user_id' => $guardian->id,
'dependent_user_id' => $dependent->id,
'relationship_type' => $data['relationship_type'],
'is_billing_contact' => $data['is_billing_contact'] ?? false,
]);
return $dependent;
}
/**
* Get all invoices where the guardian is the payer.
*
* @param int $guardianId The guardian user ID
* @return \Illuminate\Database\Eloquent\Collection The invoices
*/
public function getFamilyInvoices(int $guardianId)
{
return Invoice::where('payer_user_id', $guardianId)
->with('student')
->get();
}
}