Installation
composer require niraj/crudstarter --dev
php artisan vendor:publish --tag=crudstarter-config
Generate a Dashboard (One-Time Setup)
php artisan gen:dashboard
/resources/views/dashboard.blade.php.First CRUD Generation
php artisan gen:crud User --fields="name:string,email:string,password:encrypted:string"
app/Models/User.php)database/migrations/..._create_users_table.php)app/Http/Controllers/Admin/UserController.php)resources/views/admin/users/...)routes/web.php and routes/api.php)Access the CRUD Interface
/admin/users in your browser to interact with the generated CRUD./config/crudstarter.php – Adjust namespaces, view paths, or default behaviors.php artisan vendor:publish --tag=crud-stub), customize templates for models, controllers, or views in /stubs/.php artisan gen:crud Post --fields="title:string,slug:unique:string,content:text,is_published:boolean"
Post with validation, pagination, and search./api/posts) for headless integrations.fieldName:type (e.g., name:string, price:decimal:8,2).php artisan gen:crud Product --fields="name:string,price:decimal:8,2,stock:integer,description:text"
--options to customize:
php artisan gen:crud Product --fields="..." --options="--with-soft-deletes --with-timestamps"
Generate API-only CRUD:
php artisan gen:api Product --fields="name:string,price:decimal:8,2"
Output:
routes/api.php).store, update, destroy, etc.Integration Tip: Extend the generated controller to add custom logic:
// app/Http/Controllers/API/ProductController.php
public function store(Request $request) {
$validated = $request->validate([
'name' => 'required|string|max:255',
'price' => 'required|numeric',
// Custom validation
'price' => 'min:0',
]);
return parent::store($request);
}
Pattern: Override default views by copying generated files to /resources/views/admin/{model}/.
Example:
/vendor/niraj/crudstarter/src/Resources/views/admin/crud/index.blade.php to /resources/views/admin/products/index.blade.php.Integration Tip:
Use @include('crudstarter::partials._form') to reuse form partials while adding custom fields.
Pattern: Define relationships in the --fields argument:
php artisan gen:crud Order --fields="user:id,items:hasMany,total:decimal:10,2"
Outcome:
user_id).items (if hasMany).Integration Tip: Customize relationship queries in the model:
public function items() {
return $this->hasMany(Item::class)->orderBy('created_at', 'desc');
}
Product:
php artisan make:policy ProductPolicy --model=Product
public function __construct() {
$this->authorizeResource(Product::class, 'product');
}
rules() method.php artisan gen:seeder Product --count=5
--with-faker to populate fake data:
php artisan gen:seeder Product --count=10 --with-faker
spatie/laravel-permission, extend the generated controller:
use Spatie\Permission\Traits\HasRoles;
class ProductController extends Controller {
use HasRoles;
public function index() {
$this->authorize('viewAny', Product::class);
// ...
}
}
php artisan vendor:publish --tag=crudstarter-lang
/resources/lang/{locale}/crudstarter.php.// In the controller
public function getCustomButtons() {
return [
'publish' => [
'label' => 'Publish',
'class' => 'btn-success',
'route' => 'admin.products.publish',
'method' => 'POST',
],
];
}
routes/web.php:
Route::post('/admin/products/{product}/publish', [ProductController::class, 'publish'])->name('admin.products.publish');
created, updated):
// app/Listeners/ProductCreatedListener.php
public function handle($event) {
// Send notification, log, etc.
}
EventServiceProvider:
protected $listen = [
'niraj\crudstarter\Events\CrudCreated' => [
ProductCreatedListener::class,
],
];
string but using it as a relationship.relationship:model in --fields:
php artisan gen:crud Order --fields="user:relationship:User"
/admin/users vs. /users).config/crudstarter.php:
'route_prefix' => 'backend',
routes/web.php:
Route::prefix('admin')->group(function () {
Route::resource('products', ProductController::class);
});
php artisan vendor:publish --tag=crud-stub --force
php artisan gen:crud Product --force
--with-soft-deletes:
php artisan gen:crud Product --fields="..." --options="--with-soft-deletes"
use SoftDeletes;
--api-namespace to customize the API namespace:
php artisan gen:api Product --api-namespace=v1
How can I help you explore Laravel packages today?