feat(Structure & IDE Helper)

This commit is contained in:
2025-10-24 14:09:54 +02:00
parent bccb1866c6
commit ec1e45d1ec
32 changed files with 33930 additions and 122 deletions

View File

@@ -6,6 +6,8 @@ use App\Models\Service;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

View File

@@ -3,8 +3,11 @@
namespace App\Http\Controllers\Forms;
use App\Http\Controllers\Controller;
use App\Http\Requests\Forms\MembershipRequest;
use App\Models\Member;
use App\Models\Membership;
use App\Models\Package;
use App\Services\MemberService;
use Carbon\Carbon;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
@@ -12,62 +15,45 @@ use Inertia\Inertia;
class MembershipFormController extends Controller
{
public function __construct(protected MemberService $memberService) {}
/**
* Show the contact form page.
*/
public function create()
{
return Inertia::render('forms/membership');
return Inertia::render('forms/membership', [
'plans' => Package::query()
->where('is_active', true)
->select('id', 'name', 'price', 'description')
->get()
]);
}
/**
* Handle an incoming membership form request.
*
*/
public function store(Request $request): RedirectResponse
public function store(MembershipRequest $request): RedirectResponse
{
$request->validate([
'lastname' => 'required|string|max:255',
'firstname' => 'required|string|max:255',
'email' => 'required|email|max:255',
'company' => 'required|string|max:255',
'date_of_birth' => 'required|date',
'address' => 'required|string|max:255',
'zipcode' => 'required|string|max:255',
'city' => 'required|string|max:255',
'phone1' => 'required|string|max:255',
// Captcha
]);
$validated = $request->validated();
// New Member with status pending
try {
$this->memberService->registerNewMember($validated);
} catch (\Throwable $e) {
\Log::error('Erreur lors de la création dun membre', [
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
'data' => $validated,
]);
$member = new Member();
$member->status = 'pending';
$member->nature = 'physical';
//$member->group_id = '2';
$member->lastname = $request->lastname;
$member->firstname = $request->firstname;
$member->email = $request->email;
$member->company = $request->company ?? null;
$member->date_of_birth = Carbon::parse($request->date_of_birth)->format('Y-m-d H:i:s') ?? null;
$member->address = $request->address;
$member->zipcode = $request->zipcode;
$member->city = $request->city;
$member->country = 'FR';
$member->phone1 = $request->phone1;
return redirect()
->route('membership')
->with('error', __('memberships.subscription.failed'));
}
$member->save();
$membership = new Membership();
$membership->member()->associate($member);
$membership->save();
// Event for sending notification to admin
// Event for sending notification to member
return redirect()->route('membership')->with('success', __('Your message has been sent successfully!'));
return redirect()
->route('membership')
->with('success', __('memberships.subscription.success'));
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Http\Requests\Forms;
use Illuminate\Foundation\Http\FormRequest;
class MembershipRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
// Member
'lastname' => 'required|string|max:255',
'firstname' => 'required|string|max:255',
'email' => 'required|email|max:255',
'company' => 'required|string|max:255',
'address' => 'required|string|max:255',
'zipcode' => 'required|string|max:255',
'city' => 'required|string|max:255',
'phone1' => 'required|string|max:255',
'group_id' => 'required|string|max:255',
// Membership
'package' => 'required|string|max:255',
'amount' => 'required|string|max:255',
];
}
}

View File

@@ -4,6 +4,31 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property string|null $lastname
* @property string|null $firstname
* @property string|null $email
* @property string|null $address
* @property string|null $subject
* @property string|null $message
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read string $full_name
* @method static \Illuminate\Database\Eloquent\Builder<static>|Contact newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Contact newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Contact query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Contact whereAddress($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Contact whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Contact whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Contact whereFirstname($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Contact whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Contact whereLastname($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Contact whereMessage($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Contact whereSubject($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Contact whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Contact extends Model
{
protected $fillable = [

View File

@@ -7,6 +7,60 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* @property int $id
* @property int|null $user_id
* @property string|null $keycloak_id
* @property string $status
* @property string $nature
* @property int|null $group_id
* @property string|null $lastname
* @property string|null $firstname
* @property string $email
* @property string|null $company
* @property string|null $date_of_birth
* @property string|null $address
* @property string|null $zipcode
* @property string|null $city
* @property string|null $country
* @property string|null $phone1
* @property string|null $phone2
* @property int $public_membership
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $deleted_at
* @property-read string $full_name
* @property-read \App\Models\MemberGroup|null $group
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Membership> $memberships
* @property-read int|null $memberships_count
* @property-read \App\Models\User|null $user
* @method static \Database\Factories\MemberFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereAddress($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereCity($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereCompany($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereCountry($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereDateOfBirth($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereFirstname($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereGroupId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereKeycloakId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereLastname($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereNature($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member wherePhone1($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member wherePhone2($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member wherePublicMembership($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Member whereZipcode($value)
* @mixin \Eloquent
*/
class Member extends Model
{
use HasFactory;
@@ -27,7 +81,10 @@ class Member extends Model
'country',
'phone1',
'phone2',
'public_membership'
'public_membership',
'package_id',
'amount',
'payment_status'
];
public static function getAttributeLabel(string $attribute): string

View File

@@ -5,6 +5,28 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* @property int $id
* @property string $identifier
* @property string $name
* @property string|null $description
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $deleted_at
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Member> $members
* @property-read int|null $members_count
* @method static \Illuminate\Database\Eloquent\Builder<static>|MemberGroup newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|MemberGroup newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|MemberGroup query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|MemberGroup whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|MemberGroup whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|MemberGroup whereDescription($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|MemberGroup whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|MemberGroup whereIdentifier($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|MemberGroup whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|MemberGroup whereUpdatedAt($value)
* @mixin \Eloquent
*/
class MemberGroup extends Model
{
protected $fillable = [

View File

@@ -8,6 +8,41 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* @property int $id
* @property int $member_id
* @property int|null $admin_id
* @property int $package_id
* @property string $start_date
* @property string|null $end_date
* @property string $status
* @property string $amount
* @property string $payment_status
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $deleted_at
* @property-read \App\Models\User|null $author
* @property-read \App\Models\Member $member
* @property-read \App\Models\Package $package
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Service> $services
* @property-read int|null $services_count
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership whereAdminId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership whereAmount($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership whereEndDate($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership whereMemberId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership wherePackageId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership wherePaymentStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership whereStartDate($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Membership whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Membership extends Model
{
protected $fillable = [

View File

@@ -5,6 +5,30 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* @property int $id
* @property string $identifier
* @property string $name
* @property string|null $description
* @property string $price
* @property int $is_active
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $deleted_at
* @method static \Illuminate\Database\Eloquent\Builder<static>|Package newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Package newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Package query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Package whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Package whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Package whereDescription($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Package whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Package whereIdentifier($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Package whereIsActive($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Package whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Package wherePrice($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Package whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Package extends Model
{
protected $fillable = [

View File

@@ -5,6 +5,32 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
/**
* @property int $id
* @property string $identifier
* @property string $name
* @property string|null $description
* @property string $url
* @property string|null $icon
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $deleted_at
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Membership> $memberships
* @property-read int|null $memberships_count
* @method static \Illuminate\Database\Eloquent\Builder<static>|Service newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Service newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Service query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Service whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Service whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Service whereDescription($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Service whereIcon($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Service whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Service whereIdentifier($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Service whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Service whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Service whereUrl($value)
* @mixin \Eloquent
*/
class Service extends Model
{
protected $fillable = [

View File

@@ -10,6 +10,41 @@ use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Spatie\Permission\Traits\HasRoles;
/**
* @property int $id
* @property string $name
* @property string $email
* @property \Illuminate\Support\Carbon|null $email_verified_at
* @property string $password
* @property string|null $remember_token
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Member> $members
* @property-read int|null $members_count
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
* @property-read int|null $notifications_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Permission\Models\Permission> $permissions
* @property-read int|null $permissions_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Permission\Models\Role> $roles
* @property-read int|null $roles_count
* @method static \Database\Factories\UserFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder<static>|User newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|User newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|User permission($permissions, $without = false)
* @method static \Illuminate\Database\Eloquent\Builder<static>|User query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|User role($roles, $guard = null, $without = false)
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereEmailVerifiedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|User wherePassword($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|User withoutPermission($permissions)
* @method static \Illuminate\Database\Eloquent\Builder<static>|User withoutRole($roles, $guard = null)
* @mixin \Eloquent
*/
class User extends Authenticatable
{
use HasRoles, HasFactory, Notifiable, TwoFactorAuthenticatable;

View File

@@ -0,0 +1,59 @@
<?php
namespace App\Services;
use App\Models\Member;
use App\Models\MemberGroup;
use App\Models\Package;
use Carbon\Carbon;
class MemberService
{
public function __construct()
{
// No repositories used in this project
}
public function registerNewMember(array $data): Member
{
// Check if the member already exists
$member = Member::where('email', $data['email'])->first();
if (! $member) {
// Create a new member
$member = new Member();
$member->status = 'pending';
$member->nature = 'physical';
$member->group_id = MemberGroup::where('identifier', 'website')->first()->id ?? null;
$member->lastname = $data['lastname'];
$member->firstname = $data['firstname'];
$member->email = $data['email'];
$member->company = $data['company'] ?? null;
$member->date_of_birth = Carbon::parse($data['date_of_birth'])->format('Y-m-d H:i:s') ?? null;
$member->address = $data['address'];
$member->zipcode = $data['zipcode'];
$member->city = $data['city'];
$member->country = 'FR';
$member->phone1 = $data['phone1'];
$member->save();
}
$package = Package::where('id', $data['package_id'])
->where('is_active', true)
->firstOrFail();
// Create a new membership
$member->memberships()->create([
'status' => 'pending',
'package_id' => $package->id ?? null,
'amount' => $data['amount'],
'payment_status' => 'pending',
]);
// Notify Admin
return $member;
}
}