footility/foocrud
footility/foocrud is a Laravel/PHP package for building CRUD features quickly. Provides scaffolding and helpers to create, read, update, and delete resources with less boilerplate, aimed at speeding up admin panels and basic data management.
Installation
composer require footility/foocrud
Publish the config (if available) and run migrations:
php artisan vendor:publish --provider="Footility\Foocrud\FoocrudServiceProvider"
php artisan migrate
Basic Setup
Register the package in config/app.php under providers:
Footility\Foocrud\FoocrudServiceProvider::class,
First Use Case: Quick CRUD for a Model
Assume you have a Post model. Create a controller to leverage foocrud:
use Footility\Foocrud\CrudController;
class PostCrudController extends CrudController
{
public function model()
{
return \App\Models\Post::class;
}
}
Define a route in routes/web.php:
Route::resource('posts', \App\Http\Controllers\PostCrudController::class);
Explore the README Check the GitHub README for model binding, field customization, and view overrides.
Model Binding
Extend CrudController and override model() to bind to any Eloquent model:
public function model()
{
return \App\Models\User::class;
}
Field Customization
Use crudFields() to define which fields appear in forms/views:
protected function crudFields()
{
return [
'name', 'email', 'is_active'
];
}
View Overrides Override default views by publishing assets:
php artisan vendor:publish --tag=foocrud-views
Then customize resources/views/vendor/foocrud/.
Authorization Integrate with Laravel’s gates/policies:
public function authorizeCreate()
{
return auth()->user()->can('create', $this->model());
}
API Support
Extend CrudController for API responses:
public function store(Request $request)
{
$data = $this->create($request);
return response()->json($data, 201);
}
foocrud’s JS assets for dynamic forms (if provided).validateCreate()/validateUpdate() for custom rules.with() in model() or nested forms.Missing Config
If views/routes fail, ensure foocrud is registered in config/app.php and config published.
Model Not Found
Verify the model() method returns a fully qualified class name (e.g., \App\Models\Post).
Field Mismatches If fields don’t render, check:
$fillable array.crudFields().Route Conflicts
Avoid naming conflicts with existing Route::resource calls. Use unique prefixes:
Route::prefix('admin')->resource('posts', PostCrudController::class);
dd($this->model()); // Verify class name in controller.
php artisan vendor:publish --tag=foocrud-views --force
APP_DEBUG=true in .env to surface template errors.Custom Actions
Add methods like actionDelete() to extend functionality:
public function actionDelete($id)
{
$model = $this->model::findOrFail($id);
$model->delete();
return redirect()->route('posts.index')->with('success', 'Deleted!');
}
Hooks
Override lifecycle methods (e.g., beforeCreate(), afterUpdate()).
Blade Directives
If the package uses directives (e.g., @crudForm), check app/Providers/AppServiceProvider for registration.
Testing Mock the controller in PHPUnit:
$controller = new PostCrudController();
$controller->model = Mockery::mock(\App\Models\Post::class);
How can I help you explore Laravel packages today?