Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/Filament/Pages/Auth/Login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Filament\Pages\Auth;

use Filament\Pages\Auth\Login as BasePage;

class Login extends BasePage
{
public function mount(): void
{
parent::mount();

if (\app()->environment('local')) {
$this->form->fill([
'email' => \config('app.seed.users.super.email'),
'password' => \config('app.seed.users.super.password'),
'remember' => true,
]);
}
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class LoginController extends Controller
public function show(Request $request)
{
return inertia('Login/Show', app()->environment('local', 'testing') ? [
'email' => config('app.seed.emails.super'),
'password' => '12345',
'email' => config('app.seed.users.super.email'),
'password' => config('app.seed.users.super.password'),
'remember' => true,
'redirect' => $request->query('redirect', ''),
] : []);
Expand Down
6 changes: 6 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Filament\Models\Contracts\HasName;
use Filament\Panel;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
Expand Down Expand Up @@ -62,6 +63,11 @@ protected function allPermissions(): Attribute
);
}

protected function scopeHasRoles(Builder $query, array $roles): void
{
$query->whereHas('roles', fn (Builder $query) => $query->whereIn('name', $roles));
}

public function updatePassword(?string $new_password = '')
{
if ($new_password && $new_password != $this->password) {
Expand Down
3 changes: 2 additions & 1 deletion app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function panel(Panel $panel): Panel
->default()
->id('admin')
->path('admin')
->login()
->login(\App\Filament\Pages\Auth\Login::class)
->colors([
'primary' => '#1e293b',
])
Expand All @@ -43,6 +43,7 @@ public function panel(Panel $panel): Panel
FilamentSpatieRolesPermissionsPlugin::make(),
EnvironmentIndicatorPlugin::make()
->visible(fn () => \auth()->user()?->hasRole(Role::SUPER_ADMIN) && \app()->environment() !== 'production')
->showBorder(false)
->color(fn () => match (app()->environment()) {
'production' => Color::Green,
'staging' => Color::Blue,
Expand Down
17 changes: 13 additions & 4 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
return [

'seed' => [
'emails' => [
'super' => env('SEED_SUPER_ADMIN_EMAIL', 'super@laravel-inertia-template.test'),
'admin' => env('SEED_ADMIN_EMAIL', 'admin@laravel-inertia-template.test'),
'user' => env('SEED_USER_EMAIL', 'user@laravel-inertia-template.test'),
'users' => [
'super' => [
'email' => env('SEED_SUPER_ADMIN_EMAIL', 'super@laravel-inertia-template.test'),
'password' => env('SEED_SUPER_ADMIN_PASSWORD', '12345'),
],
'admin' => [
'email' => env('SEED_ADMIN_EMAIL', 'admin@laravel-inertia-template.test'),
'password' => env('SEED_ADMIN_PASSWORD', '12345'),
],
'user' => [
'email' => env('SEED_USER_EMAIL', 'user@laravel-inertia-template.test'),
'password' => env('SEED_USER_PASSWORD', '12345'),
],
],
],

Expand Down
13 changes: 8 additions & 5 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,32 @@ public function superAdmin(?string $email = null)
{
return $this
->state(fn (array $attributes) => [
'email' => $email ?: \config('app.seed.emails.super'),
'email' => \config('app.seed.users.super.email'),
'password' => \config('app.seed.users.super.password'),
])
->afterCreating(function (User $user) {
$user->assignRole(Role::SUPER_ADMIN->value);
});
}

public function admin(?string $email = null)
public function admin()
{
return $this
->state(fn (array $attributes) => [
'email' => $email ?: \config('app.seed.emails.admin'),
'email' => \config('app.seed.users.admin.email'),
'password' => \config('app.seed.users.admin.password'),
])
->afterCreating(function (User $user) {
$user->assignRole(Role::ADMIN->value);
});
}

public function user(?string $email = null)
public function user()
{
return $this
->state(fn (array $attributes) => [
'email' => $email ?: \config('app.seed.emails.user'),
'email' => \config('app.seed.users.user.email'),
'password' => \config('app.seed.users.user.password'),
])
->afterCreating(function (User $user) {
$user->assignRole(Role::USER->value);
Expand Down
5 changes: 3 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Architecture">
<directory>tests/Architecture</directory>
</testsuite>
<directory>tests/Architecture</directory>
</testsuite>
</testsuites>
<coverage/>
<source>
Expand All @@ -20,6 +20,7 @@
<directory suffix=".php">./app/Filament</directory>
<directory suffix=".php">./app/Providers/Filament</directory>
<file>./app/Providers/HorizonServiceProvider.php</file>
<file>./app/Providers/TelescopeServiceProvider.php</file>
</exclude>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions tests/Feature/Controllers/LoginControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
->assertInertia(
fn (Assert $page) => $page
->component('Login/Show')
->where('email', config('app.seed.emails.super'))
->where('password', '12345')
->where('email', config('app.seed.users.super.email'))
->where('password', config('app.seed.users.super.password'))
->where('remember', true)
->where('redirect', '')
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@

function superAdminUser()
{
return User::whereEmail(\config('app.seed.emails.super'))->first();
return User::whereEmail(\config('app.seed.users.super.email'))->first();
}

function adminUser()
{
return User::whereEmail(\config('app.seed.emails.admin'))->first();
return User::whereEmail(\config('app.seed.users.admin.email'))->first();
}