Skip to content

Commit

Permalink
feat: add filament Donor and Status resources
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhe4rt committed May 31, 2023
1 parent c7ef23a commit aa8575f
Show file tree
Hide file tree
Showing 22 changed files with 1,698 additions and 1,015 deletions.
6 changes: 6 additions & 0 deletions .bash_history
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
php artisan make:filament-resource Donor/Status --generate
php artisan db:seed
php artisan make:filament-resource Donor/Donor --generate
php artisan forms:install
npm install && npm run dev
exit
94 changes: 94 additions & 0 deletions app/Filament/Resources/Donor/DonorResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace App\Filament\Resources\Donor;

use App\Filament\Resources\Donor\DonorResource\Pages;
use App\Filament\Resources\Donor\DonorResource\RelationManagers;
use App\Models\Donor\Donor;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class DonorResource extends Resource
{
protected static ?string $model = Donor::class;

protected static ?string $navigationGroup = 'Donor';

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

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('status_id')
->relationship('status', 'Status')
->searchable()
->required(),
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('email')
->email()
->required()
->maxLength(255),
Forms\Components\TextInput::make('full_address')
->required()
->maxLength(255),
Forms\Components\TextInput::make('job_title')
->required()
->maxLength(255),
Forms\Components\TextInput::make('social_type')
->maxLength(255),
Forms\Components\TextInput::make('social_url')
->maxLength(255),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('status_id'),
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('email'),
Tables\Columns\TextColumn::make('full_address'),
Tables\Columns\TextColumn::make('job_title'),
Tables\Columns\TextColumn::make('social_type'),
Tables\Columns\TextColumn::make('social_url'),
Tables\Columns\TextColumn::make('created_at')
->dateTime(),
Tables\Columns\TextColumn::make('updated_at')
->dateTime(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}

public static function getRelations(): array
{
return [
//
];
}

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

namespace App\Filament\Resources\Donor\DonorResource\Pages;

use App\Filament\Resources\Donor\DonorResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\CreateRecord;

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

namespace App\Filament\Resources\Donor\DonorResource\Pages;

use App\Filament\Resources\Donor\DonorResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\EditRecord;

class EditDonor extends EditRecord
{
protected static string $resource = DonorResource::class;

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

namespace App\Filament\Resources\Donor\DonorResource\Pages;

use App\Filament\Resources\Donor\DonorResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ListRecords;

class ListDonors extends ListRecords
{
protected static string $resource = DonorResource::class;

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

namespace App\Filament\Resources\Donor;

use App\Filament\Resources\Donor\StatusResource\Pages;
use App\Filament\Resources\Donor\StatusResource\RelationManagers;
use App\Models\Donor\Status;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class StatusResource extends Resource
{
protected static ?string $model = Status::class;

protected static ?string $navigationLabel = 'Donor Statuses';

protected static ?string $navigationGroup = 'Donor';

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

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime(),
Tables\Columns\TextColumn::make('updated_at')
->dateTime(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}

public static function getRelations(): array
{
return [
//
];
}

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

namespace App\Filament\Resources\Donor\StatusResource\Pages;

use App\Filament\Resources\Donor\StatusResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\CreateRecord;

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

namespace App\Filament\Resources\Donor\StatusResource\Pages;

use App\Filament\Resources\Donor\StatusResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\EditRecord;

class EditStatus extends EditRecord
{
protected static string $resource = StatusResource::class;

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

namespace App\Filament\Resources\Donor\StatusResource\Pages;

use App\Filament\Resources\Donor\StatusResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ListRecords;

class ListStatuses extends ListRecords
{
protected static string $resource = StatusResource::class;

protected function getActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
6 changes: 6 additions & 0 deletions app/Models/Donor/Donor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Donor extends Model
{
Expand All @@ -20,4 +21,9 @@ class Donor extends Model
'social_type',
'social_url'
];

public function status(): BelongsTo
{
return $this->belongsTo(Status::class);
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"laravel/tinker": "^2.8"
},
"require-dev": {
"doctrine/dbal": "^3.6",
"fakerphp/faker": "^1.9.1",
"laravel/pint": "^1.0",
"laravel/sail": "^1.18",
Expand Down
Loading

0 comments on commit aa8575f

Please sign in to comment.