86 lines
3.1 KiB
Markdown
86 lines
3.1 KiB
Markdown
# 2026-01-02
|
||
|
||
## Entry model
|
||
|
||
```bash
|
||
php artisan make:model -m Entry
|
||
```
|
||
|
||
creates skeleton files for a model and migration
|
||
|
||
we edit the migration to hold the fields we desire to be present in each record
|
||
|
||
just the minimal are added for now, paying attention to the amount of data that these may need to hold
|
||
|
||
* string (varchar): ~255 chars default.
|
||
* text: ~65 KB.
|
||
* mediumText: ~16 MB.
|
||
|
||
```bash
|
||
php artisan migrate
|
||
```
|
||
|
||
runs the migration to create the table
|
||
|
||
## Entry filament resource
|
||
|
||
```bash
|
||
❯ php artisan filament:resource Entry
|
||
|
||
The "title attribute" is used to label each record in the UI.
|
||
|
||
You can leave this blank if records do not have a title.
|
||
|
||
┌ What is the title attribute for this model? ─────────────────┐
|
||
│ title │
|
||
└──────────────────────────────────────────────────────────────┘
|
||
|
||
┌ Would you like to generate a read-only view page for the resource? ┐
|
||
│ Yes │
|
||
└────────────────────────────────────────────────────────────────────┘
|
||
|
||
┌ Should the configuration be generated from the current database columns? ┐
|
||
│ Yes │
|
||
└──────────────────────────────────────────────────────────────────────────┘
|
||
|
||
INFO Filament resource [App\Filament\Resources\Entries\EntryResource] created successfully.
|
||
```
|
||
|
||
There is more work to do on this model but for now, a new resource is added to the admin panel by which records can be added, edited, listed.
|
||
|
||
Full CRUD is already possible. This is amazing if you think how long this would have taken to create all this manually.
|
||
|
||
|
||
|
||
### slugify
|
||
|
||
```php
|
||
TextInput::make('title')
|
||
->required()
|
||
->reactive()
|
||
->afterStateUpdated(function ($state, $set): void {
|
||
$set('slug', Str::slug((string) $state));
|
||
}),
|
||
TextInput::make('slug')
|
||
->required(),
|
||
```
|
||
|
||
adding reactive and afterStateUpdted to title automatically creates a safe slug
|
||
|
||
I class things like this creature comforts of the framework and it shows how simple it can be to make fields active and updated by previous entries
|
||
|
||
For the user, this reduces error and confusion over what a url should be
|
||
|
||
### rich editor
|
||
|
||
just changing the TextInput for content
|
||
|
||
```php
|
||
RichEditor::make('content')
|
||
->columnSpanFull(),
|
||
```
|
||
|
||
to `RichEditr` gives us a 'tiptap' rich text editor
|
||
|
||
already, this is feeling more like a mini CMS, with relatively little effort
|
||
|