diff --git a/README.md b/README.md index ccded23..faa1fdc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # freezer-control Sistema de gestão de freezers +--- ### LINK DO ANTEPROJETO [https://www.youtube.com/watch?v=-Jf9hgt-Fj4&list=PLbjKo3xK3gjcOz9Ocn3H6aTtTRBypCAaA&index=2](https://www.youtube.com/watch?v=-Jf9hgt-Fj4&list=PLbjKo3xK3gjcOz9Ocn3H6aTtTRBypCAaA&index=2) + +--- +### PENDENCIAS +1. Adicionar campos CPF, Celular, Data de Nascimento na tela de cadastro `http://laravel.test/app/register` +2. Ao cadastrar, verificar pela data de nascimento informada, se o caboclo é maior de 18 anos. diff --git a/app/Filament/Resources/CustomerResource.php b/app/Filament/Resources/CustomerResource.php index 5559d4a..d4df7f0 100644 --- a/app/Filament/Resources/CustomerResource.php +++ b/app/Filament/Resources/CustomerResource.php @@ -6,39 +6,51 @@ use App\Filament\Resources\CustomerResource\RelationManagers; use App\Models\Customer; use Filament\Forms; +use Filament\Forms\Components\Select; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\SoftDeletingScope; class CustomerResource extends Resource { protected static ?string $model = Customer::class; + protected static ?string $modelLabel = 'Cliente'; + protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; public static function form(Form $form): Form { return $form ->schema([ - Forms\Components\TextInput::make('user_id') - ->required() - ->numeric(), +// Select::make('user_id') +// ->label('Usuário') +// ->searchable() +// ->relationship('user', 'name') +// ->required(), + Forms\Components\TextInput::make('name') + ->label('Nome Completo') ->required() ->maxLength(255), + Forms\Components\TextInput::make('document') + ->label('Documento') ->required() ->maxLength(255), - Forms\Components\DatePicker::make('birthdate') - ->required(), + Forms\Components\TextInput::make('email') ->email() ->required() ->maxLength(255), + + Forms\Components\DatePicker::make('birthdate') + ->label('Data Nascimento') + ->required(), + Forms\Components\TextInput::make('mobile') + ->label('Celular') ->required() ->maxLength(255), ]); @@ -48,24 +60,27 @@ public static function table(Table $table): Table { return $table ->columns([ - Tables\Columns\TextColumn::make('user_id') - ->numeric() + Tables\Columns\TextColumn::make('user.name') + ->label('Usuário') + ->searchable() ->sortable(), - Tables\Columns\TextColumn::make('name') - ->searchable(), + Tables\Columns\TextColumn::make('document') + ->label('Documento') ->searchable(), - Tables\Columns\TextColumn::make('birthdate') - ->date() - ->sortable(), + Tables\Columns\TextColumn::make('email') ->searchable(), + Tables\Columns\TextColumn::make('mobile') + ->label('Celular') ->searchable(), + Tables\Columns\TextColumn::make('created_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('updated_at') ->dateTime() ->sortable() diff --git a/app/Filament/Resources/UserResource.php b/app/Filament/Resources/UserResource.php index 1721176..ea9c42f 100644 --- a/app/Filament/Resources/UserResource.php +++ b/app/Filament/Resources/UserResource.php @@ -17,6 +17,8 @@ class UserResource extends Resource { protected static ?string $model = User::class; + protected static ?string $modelLabel = 'Usuário'; + protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; public static function form(Form $form): Form diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index d4ef644..d809e30 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -2,6 +2,7 @@ namespace App\Http\Middleware; +use Filament\Facades\Filament; use Illuminate\Auth\Middleware\Authenticate as Middleware; use Illuminate\Http\Request; @@ -12,6 +13,8 @@ class Authenticate extends Middleware */ protected function redirectTo(Request $request): ?string { - return $request->expectsJson() ? null : route('login'); + $panelID = Filament::getCurrentPanel()?->getId(); + + return $request->expectsJson() ? null : route("filament.{$panelID}.auth.login"); } } diff --git a/app/Mail/NewCustomerMail.php b/app/Mail/NewCustomerMail.php new file mode 100644 index 0000000..1b0bec3 --- /dev/null +++ b/app/Mail/NewCustomerMail.php @@ -0,0 +1,49 @@ + $this->customer, + 'secret' => $this->secret, + ] + ); + } + + public function attachments(): array + { + return []; + } +} diff --git a/app/Models/Customer.php b/app/Models/Customer.php index b3c3244..439f512 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasOne; class Customer extends Model @@ -14,8 +15,8 @@ class Customer extends Model 'birthdate' => 'date', ]; - public function user(): HasOne + public function user(): BelongsTo { - return $this->hasOne(User::class); + return $this->belongsTo(User::class); } } diff --git a/app/Models/User.php b/app/Models/User.php index 583cdd2..3034c10 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -62,8 +62,8 @@ public function canAccessPanel(Panel $panel): bool return false; } - public function customer(): BelongsTo + public function customer(): HasOne { - return $this->belongsTo(Customer::class); + return $this->hasOne(Customer::class); } } diff --git a/app/Observers/CustomerObserver.php b/app/Observers/CustomerObserver.php new file mode 100644 index 0000000..fea157a --- /dev/null +++ b/app/Observers/CustomerObserver.php @@ -0,0 +1,32 @@ + $customer->name, + 'email' => $customer->email, + 'panel' => PanelTypeEnum::APP, + 'password' => bcrypt($password), + ]); + + $customer->user_id = $user->id; + $customer->saveQuietly(); + + Mail::to($customer->email)->send(new NewCustomerMail($customer, $password)); + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 2d65aac..2a701ef 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,6 +2,8 @@ namespace App\Providers; +use App\Models\Customer; +use App\Observers\CustomerObserver; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; @@ -20,6 +22,10 @@ class EventServiceProvider extends ServiceProvider ], ]; + protected $observers = [ + Customer::class => [CustomerObserver::class], + ]; + /** * Register any events for your application. */ diff --git a/database/migrations/2024_01_16_103756_create_customers_table.php b/database/migrations/2024_01_16_103756_create_customers_table.php index 7663244..47a57f4 100644 --- a/database/migrations/2024_01_16_103756_create_customers_table.php +++ b/database/migrations/2024_01_16_103756_create_customers_table.php @@ -16,6 +16,7 @@ public function up(): void $table->foreignId('user_id') ->index() + ->nullable() ->constrained() ->cascadeOnDelete(); diff --git a/resources/views/emails/new-customer.blade.php b/resources/views/emails/new-customer.blade.php new file mode 100644 index 0000000..0913f95 --- /dev/null +++ b/resources/views/emails/new-customer.blade.php @@ -0,0 +1,18 @@ + + + + + + + Seu acesso ao {{ config('app.name') }} + + +
+

Dados de Acesso

+

Link: {{ route("filament.app.auth.login") }}

+

Usuário: {{ $customer->email }}

+

Senha: {{ $secret }}

+
+ + diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php deleted file mode 100644 index 638ec96..0000000 --- a/resources/views/welcome.blade.php +++ /dev/null @@ -1,140 +0,0 @@ - - - - - - - Laravel - - - - - - - - - -
- @if (Route::has('login')) -
- @auth - Home - @else - Log in - - @if (Route::has('register')) - Register - @endif - @endauth -
- @endif - -
-
- - - -
- - - -
- - -
- Laravel v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }}) -
-
-
-
- -