Okipa / laravel-model-json-storage

Storing your models in a json file rather than in database (single or few lines recording) can be a good option. This package saves you to create a table for a ridiculous amount of lines, improves the data recovery performances, and allows you to store and access to your models from a json files as you would do it in database.
MIT License
25 stars 16 forks source link
json laravel model okipa package php storage

laravel-model-json-storage

Source Code Latest Version Total Downloads License: MIT Build Status Code Coverage Scrutinizer Code Quality

:warning: This package has been abandonned :warning:
Do not hesitate to contact me if you want to make it evolve and to maintain it.

Storing your models in a json file rather than in database (single or few lines recording) can be a good option.
This package saves you to create a table for a ridiculous amount of lines, improves the data recovery performances, and allows you to store and access to your models from a json files as you would do it in database.


To read before use

Please keep in mind that :


Installation


Usage

First, add the ModelJsonStorage trait in your model.

class MyTestModel extends Illuminate\Database\Eloquent\Model
{
    use Okipa\LaravelModelJsonStorage\ModelJsonStorage;

    [...]
}

Then, just manipulate your model normally.
After a storage, you will see a json file named with your model title in the path defined in the model-json-storage config file.

$testModel = app(MyTestModel::class)->create([
    'name' => 'John Doe',
    'email' => 'john@doe.com',
    'password' => Hash::make('secret'),
]);
$testModel = app(MyTestModel::class)->all();
$testModel = app(MyTestModel::class)->where('email', 'john@doe.com')->first();
$testModel->update([
    'name' => 'Gary Cook'
]);
$testModel->delete();

Customize configuration

To personalize the package configuration, you have to publish it first with the following script :

php artisan vendor:publish --tag=model-json-storage::config

Then, open the published package configuration file (config/model-json-storage.php) and override the default configuration by setting your own values for the following items :


API

The most used query-related and model-related methods have been overridden to allow you to use your json stored model as usual.
Retrieve the list of the available methods bellow.
However, if you want to add a method for your personal needs, do not hesitate to improve this package with a PR.

Available Illuminate\Database\Eloquent\Model methods

Available Illuminate\Database\Query\Builder methods

Available Illuminate\Database\Concerns\BuildsQueries methods