Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- filament initialization #223

Merged
merged 2 commits into from
Apr 10, 2024
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
74 changes: 74 additions & 0 deletions app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

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"),
];
}
}
13 changes: 13 additions & 0 deletions app/Filament/Resources/UserResource/Pages/CreateUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

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

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

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

declare(strict_types=1);

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(),
];
}
}
21 changes: 21 additions & 0 deletions app/Filament/Resources/UserResource/Pages/ListUsers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

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(),
];
}
}
60 changes: 60 additions & 0 deletions app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

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
Loading