authanram / laravel-flatfile
WORK IN PROGRESS
Fund package maintenance!
authanram
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:package
Requires
- php: ^8.1.4
- calebporzio/sushi: ^2.4
- laravel/framework: ^9.17
Requires (Dev)
- authanram/laravel-query-monitor: ^1.0
- barryvdh/laravel-ide-helper: ^2.12
- fakerphp/faker: ^1.9.1
- mockery/mockery: ^1.4.4
- nunomaduro/collision: ^6.1
- nunomaduro/phpinsights: ^2.2
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.2
- pestphp/pest-plugin-mock: ^1.0
- pestphp/pest-plugin-parallel: ^1.1
- phpunit/phpunit: ^9.5.10
- riimu/kit-phpencoder: ^2.4
- roave/security-advisories: dev-latest
- spatie/laravel-ignition: ^1.0
- spatie/laravel-ray: ^1.29
- spatie/pest-plugin-snapshots: ^1.1
- spatie/temporary-directory: ^2.1
- vimeo/psalm: ^4.23
This package is auto-updated.
Last update: 2024-10-30 02:21:34 UTC
README
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 supportedIn 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.