Download the PHP package supaapps/supaapps-laravel-api-kit without Composer
On this page you can find all versions of the php package supaapps/supaapps-laravel-api-kit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download supaapps/supaapps-laravel-api-kit
More information about supaapps/supaapps-laravel-api-kit
Files in supaapps/supaapps-laravel-api-kit
Package supaapps-laravel-api-kit
Short Description Boilerplate & Helpers for Supaapps Laravel projects
License MIT
Informations about the package supaapps-laravel-api-kit
Supaapps Laravel API Kit
Boilerplate and helpers for Supaapps Laravel projects
Table of content
- Installation
- Usage
- Generate CRUD controller
- CRUD
- Available CRUD properties
- Properties used by
CrudIndexTrait
- Properties used by
UpdateIndexTrait
- Properties used by
DeleteIndexTrait
- CRUD Controller Override
- Override methods in
CrudIndexTrait
- Override methods in
- User signature
- Tests
- Linting
- Useful links
Installation
Usage
Generate CRUD controller
To create crud controller, run the following command:
CRUD
To get advantage of CRUD boilerplate controller, extend BaseCrudController
in your controller. Example:
Available CRUD properties
There are multiple properties you can use within your CRUD controller:
- The model for CRUD operations. (required)
Properties used by CrudIndexTrait
- Paginate the response from index response or not.
- Perform searches on single column using the
search
parameter from the request. If you want to search multiple columns use$searchSimilarFields
, see next property.
All of the upcoming properties should be array. If you want to add some logic head to CRUD controller override
- Perform a lookup for similar results in the specified columns using the
LIKE
operator with thesearch
parameter from the request.
In following example, it lockups for %supa%
in either name
or description
- Perform a lookup for exact results in the specified columns using the
=
operator with thesearch
parameter from the request.
In following example, it lockups for 1
in id
, price
or category_id
- Perform a lookup for results in the specified columns wrapping the
search
parameter from the request withDATE()
mysql function.
In following example, it lockups for 2023-09-26
in completed_at
, created_at
or updated_at
- Filter columns by exact given values. Ensure that the columns entered are in plural form.
In the following example, it will apply the query WHERE id IN (1, 2) AND code IN ('ABC')
- Filter date columns by min and max values
In the following example, it will search the records that have created_at
larger than create_at_min
and less than created_at_max
and updated_at
larger than updated_at_min
- Filter columns that are
NULL
orNOT NULL
In the following example, user wants to get the completed and not cancelled rewards. These rewards have completed_at IS NOT NULL
and cancelled_at IS NULL
- Define default order by column
In the following example, there are 2 order by rules are defined in the controller. The results will be ordered by created_at
descending and by id
ascending.
But if the request has sort
query parameter, then it will override the defaultOrderByColumns
. Example:
This will sort the results first by id
descending then by name
ascending
Properties used by UpdateIndexTrait
- Disable updates on the model.
Properties used by DeleteIndexTrait
- Enable deletion for the model.
CRUD Controller Override
If you want to add more logic to properties, you can override properties in your controller using getters. For example: you want to return different $searchExactFields
depending on a condition:
Override methods in CrudIndexTrait
-
Override
$searchSimilarFields
-
Override
$searchExactFields
-
Override
$searchDateFields
-
Override
$filters
-
Override
$dateFilters
-
Override
$isEmptyFilters
-
Get allowed list that can be ordered by
- Override
$defaultOrderByColumns
User signature
You can keep track of created
and updated
user of your model in 3 steps:
- Include required columns to your model
schema
Where auditIds
accepts 2 parameters
table
: the related table name, default:users
column
: the related column name on related table, defaultid
-
Include custom columns to your model
$fillable
property - Add observer to your model
Tests
Linting
Useful links
All versions of supaapps-laravel-api-kit with dependencies
illuminate/support Version ^10.0 || ^11.0
illuminate/http Version ^10.0 || ^11.0
illuminate/database Version ^10.0 || ^11.0
illuminate/console Version ^10.0 || ^11.0
jfcherng/php-diff Version ^6.15
symfony/var-exporter Version ^6.3