Skip to content

Commit

Permalink
- added filament package and first crud - user resource
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilpiech97 committed Apr 9, 2024
1 parent e037edc commit 38351b9
Show file tree
Hide file tree
Showing 9 changed files with 2,666 additions and 446 deletions.
73 changes: 73 additions & 0 deletions app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Blumilk\Website\Filament\Resources;

use Blumilk\Website\Filament\Resources\UserResource\Pages;
use Blumilk\Website\Models\User;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;

class UserResource extends Resource
{
protected static ?string $model = User::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->label('Imię i nazwisko')
->required()
->maxLength(255),
Forms\Components\TextInput::make('email')
->label('E-mail')
->required()
->maxLength(255)
->email()
->unique(ignoreRecord: true),
Forms\Components\TextInput::make('password')
->label('Hasło')
->required()
->password()
->confirmed(),
Forms\Components\TextInput::make('password_confirmation')
->label('Potwierdź hasło')
->required()
->password(),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make("name")
->label("Imię i nazwisko"),
Tables\Columns\TextColumn::make("email")
->label("E-mail"),
])
->filters([])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}
}
12 changes: 12 additions & 0 deletions app/Filament/Resources/UserResource/Pages/CreateUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Blumilk\Website\Filament\Resources\UserResource\Pages;

use Blumilk\Website\Filament\Resources\UserResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;

class CreateUser extends CreateRecord
{
protected static string $resource = UserResource::class;
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/UserResource/Pages/EditUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Blumilk\Website\Filament\Resources\UserResource\Pages;

use Blumilk\Website\Filament\Resources\UserResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditUser extends EditRecord
{
protected static string $resource = UserResource::class;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/UserResource/Pages/ListUsers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Blumilk\Website\Filament\Resources\UserResource\Pages;

use Blumilk\Website\Filament\Resources\UserResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListUsers extends ListRecords
{
protected static string $resource = UserResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
58 changes: 58 additions & 0 deletions app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Blumilk\Website\Providers\Filament;

use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Widgets;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;

class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->colors([
'primary' => Color::Amber,
])
->discoverResources(in: app_path('Filament/Resources'), for: 'Blumilk\\Website\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'Blumilk\\Website\\Filament\\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'Blumilk\\Website\\Filament\\Widgets')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
]);
}
}
7 changes: 2 additions & 5 deletions bootstrap/providers.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php

declare(strict_types=1);

use Blumilk\Website\Providers\AppServiceProvider;

return [
AppServiceProvider::class,
Blumilk\Website\Providers\Filament\AdminPanelProvider::class,
Blumilk\Website\Providers\AppServiceProvider::class,
];
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
"license": "MIT",
"require": {
"php": "^8.3",
"ext-intl": "*",
"ext-pdo": "*",
"codezero/laravel-localized-routes": "^4.0",
"filament/filament": "^3.2",
"guzzlehttp/guzzle": "^7.8",
"laravel/framework": "^11.0",
"laravel/sanctum": "^4.0",
Expand Down Expand Up @@ -38,7 +40,8 @@
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
"@php artisan package:discover --ansi",
"@php artisan filament:upgrade"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
Expand Down
Loading

0 comments on commit 38351b9

Please sign in to comment.