Eloquent flat file driver, on top of Sushi π£.
PHP 8.1.4 or higher, Laravel 9+
Downward compatibility is already at the doorstep.
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.
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
-
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.
Please see the contribution guide for details.
Please review our security policy on how to report security vulnerabilities.
- Daniel Seuffer
- and Contributors β€οΈ
Special thanks to Caleb Porzio, the author of the underlying package Sushi π£.
The MIT License (MIT). Please see License File for more information.