Laravel Fast Api Crud #102
anilkumarthakur60
started this conversation in
Package Suggestions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
https://github.com/anilkumarthakur60/Fast-Api-Crud
About FastApiCrud
It provides basic to advanced CRUD (Create, Read, Update, Delete) functionality for a given model.
Composer
Installation
Child Constructor method
This package has auto-discovery for laravel 6 and higher and for below you can add this in your providers array
This package is build on Top of Spatie role and permission Register in Kernel.php if you want to apply permission as well
Eample
The class has several protected properties that can be overridden in child classes:
$scopes
: An array of scopes to apply when fetching all records.$scopeWithValue
: An array of scoped values to apply when fetching all records.$loadScopes
: An array of scopes to apply when fetching a record.$loadScopeWithValue
: An array of scoped values to apply when fetching a record.$withAll
: An array of relationships to eager load when fetching all records.$withCount
: An array of relationships to count when fetching all records.$withAggregate
: An array of aggregate functions to apply when fetching all records.$loadAll
: An array of relationships to eager load when fetching a single record.$loadCount
: An array of relationships to count when fetching a single record.$loadAggregate
: An array of aggregate functions to apply when fetching a single record.$isApi
: A boolean indicating whether the controller is being used as an API or not.$forceDelete
: A boolean indicating whether to perform a soft delete or a hard delete.$applyPermission
: A boolean indicating whether to apply permission or not.$deleteScopes
: An array of scopes to apply when deleting a record.$deleteScopeWithValue
: An array of scoped values to apply when deleting a record.$changeStatusScopes
: An array of scopes to apply when changing status of a record.$changeStatusScopeWithValue
: An array of scoped values to apply when changing status of a record.$restoreScopes
: An array of scopes to apply when restoring a record.$restoreScopeWithValue
: An array of scoped values to apply when restoring a record.$updateScopes
: An array of scopes to apply when updating a record.$updateScopeWithValue
: An array of scoped values to apply when updating a record.The class has several methods that correspond to basic CRUD operations:
index()
- Return Collection of all records.store()
- Create a new record.show($id)
- Return a single record.destroy($id)
Delete a record.delete()
- Bulk delete records.changeStatusOtherColumn($id,$column)
- Change specific$column
value between 0 and 1 provided from child classupdate($id)
- Update a record.changeStatus($id)
- Change status column value of a record between 0 and 1.restoreTrashed($id)
- Restore a soft deleted record.restoreAllTrashed()
- Restore all soft deleted records.forceDeleteTrashed($id)
- Hard delete a soft deleted record.There are also two helper methods,
error()
andsuccess()
, that return a JSON response with a message and data. These are used to standardize error and success responses across the controller.for example
This package has also featured for making service ,action,trait file also
After installation, the command
php artisan make:service {name} {--N|noContract}
will be available.Create services files
For example, the command
php artisan make:service createUser
will generate a service file calledCreateUserService.php
located inapp/Services/CreateUser
.It will also generate an interface (contract) called
CreateUserContract.php
located inapp/Services/Contracts
.Create services for models
Adding a
--service
or-S
option is now available when creating a model.For example, the command
php artisan make:model Post --service
orphp artisan make:model Post -S
will generate a model with service too.The command
php artisan make:model Post --all
orphp artisan make:model Post -a
will now generate a model, migration, factory, seeder, policy, controller, form requests and service.Contracts
Adding a
--noContract
or-N
option will prevent the commands from implementing any contract and will not create any contract file.If you never need any contracts. Publish the config file and then turn the with_interface value to false in the config file.
Beta Was this translation helpful? Give feedback.
All reactions