Download the PHP package miladshm/controller-helpers without Composer
On this page you can find all versions of the php package miladshm/controller-helpers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download miladshm/controller-helpers
More information about miladshm/controller-helpers
Files in miladshm/controller-helpers
Package controller-helpers
Short Description Resource controller methods in traits
License
Informations about the package controller-helpers
Controller CRUD Helpers
Overview
This package is a set of helper traits for Laravel controllers. It provides a convenient and reusable way to handle common tasks such as API datatable, data storage, and data update and other crud operations in Laravel applications.
Install
Configuration
Usage
API Datatable
``
Set filters
``
Set default order
``
Set default page length
``
Set table columns to be in response
``
Set columns and first-hand relations to searching within
``
Set pagination type
You can choose index pagination type between default, simple and cursor paginator.
``
Store method with HasStore trait
The HasStore trait is part of the miladshm/controller-helpers package and is designed to handle the creation of new model instances in Laravel controllers. It provides a convenient and reusable way to perform common tasks related to storing data in your application.
Usage
To use the HasStore trait in your Laravel controller, follow these steps:
- Include the trait in your controller class:
``
- Implement the necessary methods and properties:
Define the model class used by the trait:
``
Override the storeCallback method if you need to perform additional actions after a new model instance is created:
``
Override the prepareForStore method if you need to perform any necessary preparations before a new model instance is created:
``
- Implement the validation logic:
Implement the requestClass
method to define the form request class for the incoming request data:
``
- Customizing the response data:
If you want to customize the response when the new model instance is created, you can implement the
getJsonResourceClass
method and return your desired Api Resource Class
:
``
That's it! You now have a working implementation of the HasStore trait in your Laravel controller. You can customize the trait further to fit your specific needs.
Update data with HasUpdate trait
The HasUpdate trait is part of the miladshm/controller-helpers
package and is designed to handle the updating of
specific items in your Laravel application. It provides a convenient and reusable way to perform common tasks related to
updating data in your controllers.
Usage
To use the HasUpdate
trait in your Laravel controller, follow these steps:
- Include the trait in your controller class:
``
- Implement the necessary methods and properties:
Define the model class used by the trait:
``
Override the prepareForUpdate method if you need to perform any necessary preparations before updating a model instance:
``
Override the updateCallback method if you need to perform additional actions after a model instance is updated:
``
Validation logic can be implemented by overriding the updateRequestClass
method (Optional):
if this method not implemented trait will use the class that provided by requestClass
``
That's it! You now have a working implementation of the HasUpdate trait in your Laravel controller. You can customize the trait further to fit your specific needs.
Change Position
Introduction:
The HasChangePosition trait is designed to provide a method for changing the position of an item in a sorted list. It uses the provided ChangePositionRequest to determine the direction of movement. This document will guide you through the usage of this trait in your Laravel application.
Usage:
- Include the trait in your controller class:
``
- Define the model used in the trait:
``
- Implement the filters method (optional): If you need to apply any filters to the query when retrieving the adjacent item, you can override the filters method. This method should accept a query builder instance and return the modified query builder.
``
- Define the getPositionColumn method (optional): If the name of the column used for sorting is different from the default (order_column), you can override the getPositionColumn method to return the correct column name.
``
Remember to handle any exceptions that may be thrown by the changePosition method, such as ValidationException if the item cannot be moved in the specified direction.
That's it! You now have a working implementation of the HasChangePosition trait in your Laravel application.