Download the PHP package luezoid/laravel-core without Composer

On this page you can find all versions of the php package luezoid/laravel-core. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-core

Laravel Core Package

Luezoid came up with a compact way to help one creating the APIs very fast & without much hassle. Using this package, one case easily create simple CRUD operations in Laravel framework in couple of minutes with just creating a few files & configuring the components. With a lot of efforts and deep analysis of day-to-day problems (we) developers faced in the past, we came up with a sub-framework of it's own kind to simplify & fasten up the REST APIs building process.

A few cool features of this package are:

  1. Simplest & fastest way to create CRUDs.
  2. Pre-built support to define table columns which are to be specifically excluded before creating/updating a record(in default CRUD).
  3. Pre-built Search & Filters ready to use with just configuring components.
  4. Pre-built Pagination & Ordering of records ready in a Standard communication format.
  5. Relationship's data in the APIs(GET) is just a config thing.
  6. Better way to correctly fire an event upon successful completion of an action.
  7. File uploads has never been so easy before. Upload to local filesystem or AWS S3 bucket on the go.
  8. Pre-built feature rich Service classes eg. UtilityService, etc.
  9. Nested Related models can be queried with simple config based approach from the code components.
  10. On the go SELECT & Relation filters can be passed with JSON & object operator(->) in query params to select particular columns from a table(and related objects defined in models) making the API's response with less garbage data instead of writing custom query every time a new endpoint is created.
  11. Generic/Open Search over a set of related objects(tables) with simple Array based config.

    Note: For a complete working example of all these feature with core package pre-configured is available on this repository luezoidtechnologies/laravel-core-base-repo-example.

Installation

We recommend using Composer to install this package. This package supports Laravel versions >= 5.x.

composer require "luezoid/laravel-core"     # For latest version of Laravel (>=10.x)
composer require "luezoid/laravel-core:^9.0"    # For Laravel version 9.x
composer require "luezoid/laravel-core:^8.0"    # For Laravel version 8.x
composer require "luezoid/laravel-core:^7.0"    # For Laravel version 7.x
composer require "luezoid/laravel-core:^6.0"    # For Laravel version 6.x
composer require "luezoid/laravel-core:^5.0"    # For Laravel version 5.x

Next, configure your app/Exceptions/Handler.php and extend it with Luezoid\Laravelcore\Exceptions\Handler. Sample file can be seen here.

1. Creating CRUD

Using this packages adds an extra entity between the Controller & Model paradigm in a normal MVC architecture. This extra entity we are referring here is called Repository. A Repository is a complete class where your whole business logic resides from getting the processed data from a Controller and saving it into database using Model(s). By using Repository as an intermediate between Controller & Model, we aim at maintaing clean code at Controller's end and making it a mediator which only receives data(from View, typically a REST route), validate it against the defined validation rules(if any, we uses Request class to define such rules), pre-process it(for eg. transform camelCased data from front-end into snake_case) & sending business cooked data back the View.

Let's start with creating a simple Minions CRUD.

We have sample MinionRepository. Add these files into your application & adjust the namespaces accordingly. Then create a Route resource as below in routes/api.php and we are all ready:

Route::resource('minions', 'MinionController', ['parameters' => ['minions' => 'id']]);

Assuming your local server is running on port: 7872, try hitting REST endpoints as below:

  1. POST /minions

     curl -X POST \
      http://localhost:7872/api/minions \
      -H 'Content-Type: application/json' \
      -H 'cache-control: no-cache' \
      -d '{
        "name": "Stuart",
        "totalEyes": 2,
        "favouriteSound": "Grrrrrrrrrrr",
        "hasHairs": true
    }'
  2. PUT /minions/1

    curl -X PUT \
      http://localhost:7872/api/minions/1 \
      -H 'Content-Type: application/json' \
      -H 'cache-control: no-cache' \
      -d '{
        "name": "Stuart - The Pfff",
        "totalEyes": 2,
        "favouriteSound": "Grrrrrrrrrrr Pffffff",
        "hasHairs": false
    }'
  3. DELETE /minions/1

    curl -X DELETE \
      http://localhost:7872/api/minions/1 \
      -H 'cache-control: no-cache'
  4. GET /minions

    curl -X GET \
      http://localhost:7872/api/minions \
      -H 'cache-control: no-cache'
  5. GET /minions/2

    curl -X GET \
      http://localhost:7872/api/minions/2 \
      -H 'cache-control: no-cache'

2. Exclude columns for default POST & PUT request(s)

Refer the CRUD:

// To exclude the key(s) if present in request body for default POST CRUD routes eg. POST /minions
public $createExcept = [
    'id'
];

// To exclude the key(s) if present in request body for default PUT CRUD routes eg. PUT /minions/1
public $updateExcept = [
    'total_eyes',
    'has_hairs'
];

The major advantage for using such config in the model in the first place is: to provide a clean & elegant way & to simply reduce the coding efforts to be done just before saving the whole data into table. Typical examples could be:

  1. You don't want to save a column value say is_email_verified if an attacker sends it the request body of POST /users; just add it into $createExcept. You need not to exclude this specifically in the codes/or request rules.
  2. You don't want to update a column say username if an attacker sends it the request body of PUT /users/{id}; just add it into $updateExcept. You need not to exclude this specifically in the codes/or request rules.

3. Searching & Filters

You can simply search over the list of available column(s) in the table for all GET requests. Let's begin with examples:

4. Pagination & Ordering

Did you notice the response of GET endpoint we just created above? Let's take a look in brief. Refer the response of GET /minions API.

{
  "message": null,
  "data": {
    "items": [
      {},
      {},
      ...
    ],
    "page": 1,      // tells us about the current page
    "total": 6,     // tells us the total results available (matching all the query params for searching/filtering applied)
    "pages": 1,     // total pages in which the whole result set is distributed
    "perpage": 15   // total results per page
  },
  "type": null
}

Pretty self explanatory, eh?

You can pass query param perpage=5 (to limit the per page size). Similarly, the page=2 will grab the results of page 2.

For ordering the result set by a particular column, just send query param key orderby with the name of column & a separate key order with value ASC for ascending (or) DESC for sorting in descending order. By default, results are sorted in descending order.

Paginating & Ordering the results has never been so easy before :)

Note: Any GET(index) route retrieving results from a Repository (eg.MinionRepository) extending \Luezoid\Laravelcore\Repositories\EloquentBaseRepository::getAll() is all ready with such pagination & ordering. Make sure to use this pre-built feature & save time for manually implementing these features for every endpoint & grab a pint of beer to chill.

5. Relationship's data

Let's assume each Minion leads a mission operated by Gru i.e. there is one-to-one relationship exists between Minion & Missions. See the missions table migrations(MinionController properties as follows:

That's it. Just a config thingy & you can see in the response each Minion object contains another object leadingMission which is an instance of Mission model lead by respective Minion.

Note: For nested relationships, you can define them appending dot(.) operator eg. employee.designations.

6. Attach Event on an action success

Let's arrange an routes/api.php:

Route::post('missions', 'MissionController@createMission')->name('missions.store');

We need to have MissionCreateJob ready for this route to work. Also we need to have an Event say MissionCreateJob under property public $event = BringMinionToLabEvent::class; Now try hitting the route POST /missions as follows:

curl -X POST \
  http://localhost:7872/api/missions \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
    "name": "Steal the Moon! Part - 4",
    "description": "The first moon landing happened in 1969. Felonius Gru watched this historic moment with his mother and was inspired by the landing to go to outer space just like his idol Neil Armstrong.",
    "minionId": 2
}'

You should be able to see a log entry under file storage/logs/laravel.log which is the action we had set in the event BringMinionToLabEvent.

7. File Upload

With this package, file upload is just a config thing away. Publish the file.php configuration file to the config directory with below command:

php artisan vendor:publish --tag=luezoid-file-config

Configure the new type representing a specific module eg. MINION_PROFILE_PICTURE as per your requirement, define the validation(if any), valid_file_types allowed, local_path(for local filesystem), etc. A sample type named EXAMPLE is added by default for reference. Next, add the below code in AppServiceProvide:

$this->app->bind(\Luezoid\Laravelcore\Contracts\IFile::class, function ($app) {
    if (config('file.is_local')) {
        return $app->make(\Luezoid\Laravelcore\Files\Services\LocalFileUploadService::class);
    }
    return $app->make(\Luezoid\Laravelcore\Files\Services\SaveFileToS3Service::class);
});

Next, create a route as below:

Route::post('files', '\Luezoid\Laravelcore\Http\Controllers\FileController@store')->name('files.store');

Now, you are all set to upload files.

curl -X POST \
  http://localhost:7872/api/files \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F type=EXAMPLE \
  -F file=@/home/choxx/Desktop/a61113f5afc5ad52eb59f98ce293c266.jpg

The response body will have an id, url, and a few other fields representing the storage location & other details for the uploaded file. See sample here. This id field you could use to store in your table as foreign key column & make hasOne() relation with the records & use them as per need.

Moreover, in the config itself you could configure if local filesystem has to be used for uploads or on the go AWS S3 bucket. For using S3 bucket, you need to configure AWS credentials in .env file:

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=

Isn't is awesome? :)

10. Select & Relation Filters - SELECT & WHERE query over table columns (& nested relations)

This is one of the coolest feature of this package. Tired off writing query to shorten up the result set & applying filters over nested relation data? Apply such filters with simplicity with just sending simple query params. Let's see how:

11. Generic/Open Search

Need to send key searchKey via query params along with value.
In repo, define config along with models & column names to be searched on.
Usage:

$searchConfig = [  
    'abc' => [  
        'model' => Abc::class,  
        'keys' => ['name', 'field']  
    ],  
    'groups' => [
        'model' => ProductGroup::class,  
        'keys' => ['name', 'code', 'hsn_code']  
   ]
];  
return $this->search($searchConfig, $params);

License

Laravel-core is released under the MIT License. See the bundled LICENSE for details.


All versions of laravel-core with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version >=5.1
intervention/image Version ^2.4
aws/aws-sdk-php-laravel Version ^3.1
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package luezoid/laravel-core contains the following files

Loading the files please wait ....