-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: created observer for customer resource
- Loading branch information
Showing
12 changed files
with
152 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Mail; | ||
|
||
use App\Models\Customer; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Mail\Mailables\Address; | ||
use Illuminate\Mail\Mailables\Content; | ||
use Illuminate\Mail\Mailables\Envelope; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class NewCustomerMail extends Mailable implements ShouldQueue | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
public function __construct( | ||
public readonly Customer $customer, | ||
public readonly string $secret, | ||
) { | ||
} | ||
|
||
public function envelope(): Envelope | ||
{ | ||
return new Envelope( | ||
from: new Address(config('mail.from.address'), config('app.name')), | ||
subject: 'Seu acesso ao Freezer Control', | ||
); | ||
} | ||
|
||
public function content(): Content | ||
{ | ||
return new Content( | ||
view: 'emails.new-customer', | ||
with: [ | ||
'customer' => $this->customer, | ||
'secret' => $this->secret, | ||
] | ||
); | ||
} | ||
|
||
public function attachments(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Observers; | ||
|
||
use App\Enums\PanelTypeEnum; | ||
use App\Mail\NewCustomerMail; | ||
use App\Models\Customer; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\Mail; | ||
use Illuminate\Support\Str; | ||
|
||
class CustomerObserver | ||
{ | ||
public function created(Customer $customer): void | ||
{ | ||
$password = Str::random(8); | ||
|
||
$user = User::create([ | ||
'name' => $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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Seu acesso ao {{ config('app.name') }}</title> | ||
</head> | ||
<body> | ||
<div> | ||
<h1>Dados de Acesso</h1> | ||
<p><strong>Link:</strong> {{ route("filament.app.auth.login") }}</p> | ||
<p><strong>Usuário:</strong> {{ $customer->email }}</p> | ||
<p><strong>Senha:</strong> {{ $secret }}</p> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.