authanram/laravel-flatfile

WORK IN PROGRESS

Fund package maintenance!
authanram

Installs: 20

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:package

1.0.2 2022-06-28 18:01 UTC

This package is auto-updated.

Last update: 2024-03-30 00:31:09 UTC


README

CI

Eloquent flat file driver, on top of Sushi 🍣.

Requirements

PHP 8.1.4 or higher, Laravel 9+

Downward compatibility is already at the doorstep.

Installation

You can install the package via composer.

composer require authanram/laravel-flatfile

By default all files written by this package will be located at storage_path('app/flatfile').

Publish the package configuration:

php artisan vendor:publish --provider="Authanram\FlatFile\FlatFileServiceProvider"

Quickly examining the configuration file config/flatfile.php would be a good idea.

Usage Example

Here's an example of how it can be used in a very basic way:

namespace App\Models;

use Authanram\FlatFile\FlatFileModel;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Post extends Model
{
    use FlatFileModel;
    use SoftDeletes;
    
    protected $schema = [
        'title' => 'string',
        'body' => 'string',
        'published_at' => 'datetime',
    ];
    
    protected $fillable = [
        'title',
        'body',
        'published_at',
    ];
}

Somewhere else in your code:

use App\Models\Post;

Post::create([
    'title' => 'New package arrived: laravel-flatfile',
    'body' => 'Solving the issue of...',
    'published_at' => now()->addHour(),
])

This will store the following contents to storage_path('app/flatfile/post/1.json'):

{
    "id": 1,
    "title": "New package arrived: laravel-flatfile",
    "body": "Solving the issue of...",
    "published_at": "2022-06-26 11:29:27",
    "created_at": "2022-06-26 10:29:27",
    "updated_at": "2022-06-26 10:29:27",
    "deleted_at": null
}

The package ships a second serializer, supporting yaml, that would lead to the following file contents stored at storage_path('app/flatfile/post/1.yaml'):

id: 1
title: New package arrived: laravel-flatfile
body: Solving the issue of...
published_at: 2022-06-26 11:29:27
created_at: '2022-06-26 10:29:27'
updated_at: '2022-06-26 10:29:27'
deleted_at: null

Caveats

  • many-to-many relationships are currently not supported

    In order to facilitate a many-to-many relationship, please fall back to a regular DBMS supported by Eloquent or feel free to create pull request.

Contributing

Please see the contribution guide for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

Special thanks to Caleb Porzio, the author of the underlying package Sushi 🍣.

License

The MIT License (MIT). Please see License File for more information.