https://github.com/andreaselia/laravel-cruddy
WORK IN PROGRESS. Livewire Cruddy helps speed up the development of Laravel apps using the TALL stack and opinionated hook-style integration.
https://github.com/andreaselia/laravel-cruddy
Last synced: 3 months ago
JSON representation
WORK IN PROGRESS. Livewire Cruddy helps speed up the development of Laravel apps using the TALL stack and opinionated hook-style integration.
- Host: GitHub
- URL: https://github.com/andreaselia/laravel-cruddy
- Owner: andreaselia
- License: mit
- Created: 2022-01-18T13:00:04.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-22T20:00:42.000Z (over 4 years ago)
- Last Synced: 2025-12-30T22:32:24.762Z (7 months ago)
- Language: PHP
- Homepage:
- Size: 125 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Cruddy
Livewire Cruddy helps speed up the development of Laravel apps using the TALL stack and opinionated hook-style integration.

## Installation
Install the package:
```bash
composer require notano/laravel-cruddy
```
## Component
Making an existing component Cruddy friendly is as easy as extending `CrudComponent` and consuming the methods documented below. Here is a guide component:
```php
exists) {
$this->client = $client;
$this->state = $client->toArray();
$this->setTarget('update');
}
}
public function onCreate(array $data)
{
Client::create($data);
$this->redirectRoute('clients.index');
}
public function onUpdate(array $data)
{
$this->client->update($data);
$this->redirectRoute('clients.edit', $this->client);
}
public function onDelete()
{
$this->client->delete();
$this->redirectRoute('clients.index');
}
}
```
## Methods
### setupFlashMessages
This method allows you to automatically flash messages relevant to the creation/update/deletion of a record. The messages can also be customised. All messages are flashed with the "status" key.
```php
public function mount(Post $post)
{
// Default:
$this->setupFlashMessages();
// Replace "record" with a custom type:
$this->setupFlashMessages([], 'user');
// Custom messages:
$this->setupFlashMessages([
'create' => 'The record may have been created successfully.',
'update' => 'The record may have been updated successfully.',
'delete' => 'The record may have been deleted successfully.',
]);
}
```
### beforeCreate/beforeUpdate
These methods allow you to modify the data before inserting or updating.
```php
public function beforeCreate(array $input)
{
return array_merge($input, [
'uuid' => Str::uuid(),
]);
}
public function beforeUpdate(array $input)
{
return array_merge($input, [
'slug' => Str::slug($input['title']),
]);
}
```
### onCreate/onUpdate/onDelete
These methods are the main ones for all CRUD Form components.
```php
public function onCreate(array $data)
{
Client::create($data);
$this->redirectRoute('clients.index');
}
public function onUpdate(array $data)
{
$this->client->update($data);
$this->redirectRoute('clients.edit', $this->client);
}
public function onDelete()
{
$this->client->delete();
$this->redirectRoute('clients.index');
}
```
## Contributing
You're more than welcome to submit a pull request, or if you're not feeling up to it - create an issue so someone else can pick it up.