-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
243 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\CustomerResource\Pages; | ||
use App\Filament\Resources\CustomerResource\RelationManagers; | ||
use App\Models\Customer; | ||
use Filament\Forms; | ||
use Filament\Forms\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Tables; | ||
use Filament\Tables\Table; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\SoftDeletingScope; | ||
|
||
class CustomerResource extends Resource | ||
{ | ||
protected static ?string $model = Customer::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\TextInput::make('first_name') | ||
->maxLength(255), | ||
Forms\Components\TextInput::make('last_name') | ||
->maxLength(255), | ||
Forms\Components\TextInput::make('email') | ||
->email() | ||
->maxLength(255), | ||
Forms\Components\TextInput::make('phone_number') | ||
->maxLength(255), | ||
Forms\Components\Textarea::make('description') | ||
->maxLength(65535) | ||
->columnSpanFull(), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('first_name') | ||
->label('Name') | ||
->formatStateUsing(function ($record) { | ||
return $record->first_name . ' ' . $record->last_name; | ||
}) | ||
->searchable(['first_name', 'last_name']), | ||
Tables\Columns\TextColumn::make('email') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('phone_number') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('created_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
Tables\Columns\TextColumn::make('updated_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
Tables\Columns\TextColumn::make('deleted_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
]) | ||
->filters([ | ||
Tables\Filters\TrashedFilter::make(), | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
Tables\Actions\ForceDeleteBulkAction::make(), | ||
Tables\Actions\RestoreBulkAction::make(), | ||
]), | ||
]); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListCustomers::route('/'), | ||
'create' => Pages\CreateCustomer::route('/create'), | ||
'edit' => Pages\EditCustomer::route('/{record}/edit'), | ||
]; | ||
} | ||
|
||
public static function getEloquentQuery(): Builder | ||
{ | ||
return parent::getEloquentQuery() | ||
->withoutGlobalScopes([ | ||
SoftDeletingScope::class, | ||
]); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/Filament/Resources/CustomerResource/Pages/CreateCustomer.php
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,12 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\CustomerResource\Pages; | ||
|
||
use App\Filament\Resources\CustomerResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\CreateRecord; | ||
|
||
class CreateCustomer extends CreateRecord | ||
{ | ||
protected static string $resource = CustomerResource::class; | ||
} |
21 changes: 21 additions & 0 deletions
21
app/Filament/Resources/CustomerResource/Pages/EditCustomer.php
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,21 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\CustomerResource\Pages; | ||
|
||
use App\Filament\Resources\CustomerResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class EditCustomer extends EditRecord | ||
{ | ||
protected static string $resource = CustomerResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\DeleteAction::make(), | ||
Actions\ForceDeleteAction::make(), | ||
Actions\RestoreAction::make(), | ||
]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/CustomerResource/Pages/ListCustomers.php
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,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\CustomerResource\Pages; | ||
|
||
use App\Filament\Resources\CustomerResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListCustomers extends ListRecords | ||
{ | ||
protected static string $resource = CustomerResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\SoftDeletes; | ||
|
||
class Customer extends Model | ||
{ | ||
use HasFactory, SoftDeletes; | ||
|
||
protected $fillable = [ | ||
'first_name', | ||
'last_name', | ||
'email', | ||
'phone_number', | ||
'description', | ||
]; | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\odel=Customer> | ||
*/ | ||
class CustomerFactory extends Factory | ||
{ | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition(): array | ||
{ | ||
return [ | ||
'first_name' => $this->faker->firstName(), | ||
'last_name' => $this->faker->lastName(), | ||
'email' => $this->faker->unique()->safeEmail(), | ||
'phone_number' => $this->faker->phoneNumber(), | ||
'description' => $this->faker->text(), | ||
]; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
database/migrations/2023_10_15_094727_create_customers_table.php
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,34 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('customers', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('first_name')->nullable(); | ||
$table->string('last_name')->nullable(); | ||
$table->string('email')->nullable(); | ||
$table->string('phone_number')->nullable(); | ||
$table->text('description')->nullable(); | ||
$table->timestamps(); | ||
$table->softDeletes(); | ||
|
||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('customers'); | ||
} | ||
}; |
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 |
---|---|---|
|
@@ -20,5 +20,9 @@ public function run(): void | |
'email' => '[email protected]', | ||
'password' => Hash::make('12341234'), | ||
]); | ||
|
||
\App\Models\Customer::factory() | ||
->count(10) | ||
->create(); | ||
} | ||
} |