lyre / lyre
One minute CRUD with a simple command to create all resources
Requires
- php: ^8.2
- laravel/framework: ^10.0 || ^11.0 || ^12.0
- laravel/tinker: ^2.9
- spatie/laravel-activitylog: ^4.8
- spatie/laravel-permission: ^6.4
- dev-master
- 2.0.0
- 1.3.0
- 1.2.16
- 1.2.15
- 1.2.14
- 1.2.13
- 1.2.12
- 1.2.11
- 1.2.10
- 1.2.9
- 1.2.8
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.19
- 1.1.18
- 1.1.17
- 1.1.16
- 1.1.15
- 1.1.14
- 1.1.13
- 1.1.12
- 1.1.11
- 1.1.10
- 1.1.9
- 1.1.8
- 1.1.7
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.34
- 1.0.33
- 1.0.32
- 1.0.31
- 1.0.30
- 1.0.29
- 1.0.28
- 1.0.27
- 1.0.26
- 1.0.25
- 1.0.24
- 1.0.23
- 1.0.22
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
This package is auto-updated.
Last update: 2025-06-16 20:39:55 UTC
README
About Lyre
Lyre is a php package built for Laravel. Lyre works together with the rich Laravel ecosystem, and goes hand in hand with its philosophy of expressive, elegant syntax. It takes enjoyable and creative development a step further and makes you feel the harmony of it all as the elements come together. Lyre utilizes the following to create the rhythm of the future:
- Repositories, as hinted at in Laravel's container docs.
- Eloquent resources to automatically transform your responses.
- Abstracted resource controllers with all your basic CRUD, maximizing on a naturally RESTFUL API.
- Comes out of the box with spatie roles and permissions configured with Laravel policies.
- Another out of the box feature: spatie activity log configured with Eloquent observers.
- And finally, Artisan console commands to rule them all.
Lyre is accessible, powerful, and it is your next favorite tool.
Get started right away
composer require lyre/lyre
- Add
LyreServiceProvider
to your providers array underbootstrap
>providers.php
- Add
use BaseModelTrait
to your existing models. - Run
php artisan vendor:publish --provider="Lyre\Providers\LyreServiceProvider"
to publish Lyre configuration. - Clear configuration cache
php artisan lyre:all Post
-
Add your columns to your migration and migrate
-
Enable API routing (If using Laravel > 10)
php artisan install:api
- Add your model to your routes file
Route::apiResource('posts', PostController::class);
-
Consume your API!
-
Guess what? That's it.
Dependencies
Digging Deeper
RESTFULNESS
-
Lyre is naturally RESTFUL, meaning that after adding your apiResource or resource in your routes file, you will be able to create, update, and delete all records using these routes, borrowed from the above example:
GET|HEAD posts POST posts GET|HEAD posts/{post} PUT|PATCH posts/{post} DELETE posts/{post}
Hidden Gem
- Lyre comes with a bulkUpdate option that also follows the RESTFUL convention for batch operations, allowing you to efficiently update multiple records in a single request.
- All you need to do is comma separate the values in your PUT|PATCH request.
- For example:
Single Update
posts/1
Bulk Update
posts/1,2,3
Filters
Easily Handle Relationships
- To return a model with all its relationships, simply chain a with method that takes an array of relations when querying the repository like so:
$data = $this->postRepository->with(['author', 'comments'])->all();
- All you need to do is define the relationships in your model:
public function author() { return $this->belongsTo(User::class, 'user_id'); } public function comments() { return $this->hasMany(Comment::class); }
- Then override the loadResources method of the Posts resource in app>Http>Resources>Post
public static function loadResources(): array { return [ 'author' => User::class, 'comments' => Comment::class ]; }
-
Now you will be able to get your model with these relationships using a simple query string
posts/1?with=author,comments
Filters
Column Filters
- Easily return data filtered by a specific column
$data = $this->postRepository->columnFilters(['status' => 'active'])->all();
Range Filters
- Easily filter your data by range, for example, created_at!
$data = $this->postRepository->rangeFilters(['created' => [now()->subHours(24), now()])->all();
Relation Filters
- You can even return your data filtered by specific relationships!
$data = $this->postRepository->relationFilters('author' => 'id,1')->all();
Search Query
- Search through your repository!
$data = $this->postRepository->searchQuery(['search' => 'lyre'])->all();
Method Chaining
- What is more? You can chain all these methods to fine tune your query!
$data = $this->postRepository->with(['author', 'comments']) ->columnFilters(['status' => 'active']) ->rangeFilters(['created' => [now()->subHours(24), now()]) ->relationFilters('author' => 'id,1') ->searchQuery(['search' => 'lyre']) ->all()
API Query Strings
Lyre provides the following query string filters to filter all your data the way you want!
- with - A comma separated list of all the relationships that you want to return in your response
- paginate - This boolean value determines whether pagination is set, default is
true
- page - Changes the current page in a paginated request
- per_page - Changes the number of items returned in the request
- latest - Returns the latest
value
items - order - Returns ordered items, e.g.
/subjects?order=name,asc
- relation - Filter by a column in a related table, i.e.
/subjects?relation=courses,english
returns only the Subjects that belong to an English course - search - Search through all columns for a string match, e.g.
/subjects?search=physics
- startswith - Get all rows whose
NAME_COLUMN
startswith substring, e.g./subjects?startswith=b
- withcount - Get the count of a relationship, e.g.
/subjects?withcount=tasks
returns with atasks_count
field containing the number of tasks for each subject.
Known Issues
Installation
- All models must use BaseModelTrait, otherwise throws error: Call to a member function connection() on null
- Fails to publish stubs, creates empty folder. Stubs must be copied from STUBS
Collaboration
- Update version in composer.json
- Push changes to github, push tag to update Packagist
git tag x.x.x git push origin x.x.x
USING SPATIE
Using Activity Log
Publish the migration with:
php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="activitylog-migrations"
Using Roles and Permissions
Publish the migrations and the configs with:
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
Add the Spatie\Permission\Traits\HasRoles trait to your User model(s):
use Illuminate\Foundation\Auth\User as Authenticatable; use Spatie\Permission\Traits\HasRoles; class User extends Authenticatable { use HasRoles; // ... }
License
Lyre is open-sourced software licensed under the MIT license.