goodyweb/jetstream-crud
Generate Jetstream-ready CRUD modules (Create, Read, Update, Delete) for any table with one Artisan command. Scaffolds bare Livewire components and Blade views with search and pagination, so you can manage records quickly in Laravel apps.
Install the Package
composer require goodyweb/jetstream-crud dev-master
Ensure legacy_model_binding is enabled in config/livewire.php:
'legacy_model_binding' => true,
Generate a CRUD Module Run the Artisan command with your model and Livewire component names:
php artisan generate:crud --model=Person --livewire=Persons
This creates:
app/Http/Livewire/Persons.php)resources/views/livewire/persons/...)First Use Case
@livewire('persons.index')
web.php):
Route::get('/persons', [PersonsController::class, 'index'])->name('persons.index');
Model Binding The package uses Livewire’s legacy model binding to auto-load models in the component. Example:
public $person; // Auto-bound to the model ID in the URL (e.g., `/persons/1/edit`)
Form Handling
create() and update() methods in the Livewire component:
public function create()
{
$this->validate([
'name' => 'required',
'email' => 'required|email',
]);
Person::create($this->input());
session()->flash('message', 'Record created!');
}
Search and Pagination
search input field in the index view.paginate():
public function getPersonsProperty()
{
return Person::query()
->when($this->search, fn($q) => $q->where('name', 'like', "%{$this->search}%"))
->paginate(10);
}
Route Integration
Define routes in web.php for index, create, edit, and delete actions:
Route::get('/persons', [PersonsController::class, 'index'])->name('persons.index');
Route::get('/persons/create', [PersonsController::class, 'create'])->name('persons.create');
Route::post('/persons', [PersonsController::class, 'store'])->name('persons.store');
Customization
resources/views/livewire/persons/ to modify UI.Legacy Model Binding Requirement
'legacy_model_binding' => true in config/livewire.php will break model binding in routes like /persons/{id}/edit.Migration Conflicts
Livewire Component Naming
--livewire flag must match the component class name (e.g., Persons → app/Http/Livewire/Persons.php). Mismatches cause "Component not found" errors.CSRF Token Issues
@csrf or @method('PUT') for update/delete actions to avoid CSRF errors.Component Not Loading? Check:
app/Http/Livewire/.resources/views/livewire/persons/index.blade.php).@livewire directive.Validation Errors
Use dd($this->validate()) in the Livewire component to inspect validation rules and input data.
composer.json for Laravel/Livewire version constraints.Add Custom Fields
Extend the model and update the Livewire component’s rules() and input() methods:
protected $rules = [
'name' => 'required',
'email' => 'required|email',
'custom_field' => 'nullable', // Add new fields
];
Modify Queries
Override the getPersonsProperty() method to add scopes or relationships:
public function getPersonsProperty()
{
return Person::with('relationship')->paginate(10);
}
Add Actions Include custom buttons (e.g., "Export") in the Blade template and handle them in the Livewire component:
<button wire:click="export">Export</button>
public function export()
{
// Logic to export data
}
Authorization
Use Laravel’s gates/policies or Livewire’s authorize() method:
public function delete($id)
{
$this->authorize('delete', Person::find($id));
Person::find($id)->delete();
}
How can I help you explore Laravel packages today?