zofe / demo-module
The self-documenting CRUD demo of rapyd-admin: a table, a detail page and a form for Articles, each page showing its own route, component and view.
Requires
- php: ^8.2
- fakerphp/faker: ^1.23
- illuminate/config: ^11.0|^12.0|^13.0
- illuminate/contracts: ^11.0|^12.0|^13.0
- livewire/livewire: ^4.0
- zofe/rapyd-admin: ^9.6.1
Requires (Dev)
- orchestra/testbench: ^10.0|^11.0
- phpunit/phpunit: ^11.0|^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The self-documenting CRUD demo of Rapyd Admin: a table, a detail page and a
form for Articles by Authors. Every page shows, right under it, the route, the Livewire component and the Blade
view that produce it, so you see how little a CRUD takes. It is also the reference for a module packaged on its
own: same folder layout as a module generated in app/Modules, plus composer.json, a provider and tests.
Live: rapyd.dev/demo
Install
composer require zofe/demo-module php artisan migrate
Open /demo and click Populate the database (or php artisan db:seed --class="App\\Modules\\Demo\\Database\\Seeders\\DemoSeeder").
A "Crud Demo" entry appears in the admin sidebar and in the public navbar. The pages are public on purpose: it is a showcase.
Demo data and the "re-populate" link
The seeder creates 10 authors with 2 articles each and replaces whatever is there. The demo home offers a "Re-populate the demo data" link, enabled by default: on your machine you are the only user, and after creating, editing and deleting records you want a clean dataset back with one click.
On a shared, public demo turn it off, otherwise one visitor wipes what another is trying:
DEMO_REPOPULATE=false
or 'repopulate' => false in a config/demo.php of the application. The link disappears and the action answers 403;
filling an empty database stays possible. Reset the data on a schedule instead, e.g. in routes/console.php:
Schedule::command('db:seed', ['--class' => \App\Modules\Demo\Database\Seeders\DemoSeeder::class, '--force' => true])->hourly();
This is what rapyd.dev does.
What to look at
demo-module/
├─ Livewire/ Home, ArticlesTable, ArticlesView, ArticlesEdit
├─ Views/ home, articles_table, articles_view, articles_edit, menu, frontend_menu, folders
├─ Models/ Article (SSearch), Author
├─ Database/ migrations (demo_articles, demo_authors) and the seeder
├─ config.php layout, sidebar entry
├─ routes.php
├─ DemoModuleServiceProvider.php extends RapydModuleServiceProvider, $modulePath = __DIR__
└─ tests/ Testbench + Livewire tests of the three pages
ArticlesTable:WithDataTable, search through theSSearchtrait, an author filter, sorting and pagination in ax-rpd::table.ArticlesEdit: ax-rpd::editform bound to the model,$rulesas the single source of validation and of the fields kept between requests,x-rpd::rich-textfor the body.Documenter: prints the source of a file (or a route matched by a regex) with the documentation block stripped.- Copy the folder to
app/Modules/Demoand it keeps working as an app module: the provider steps aside.
Tests
composer install
composer test