authanram/laravel-flatfile

正在开发中

资助包维护!
authanram

安装: 20

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:package

1.0.2 2022-06-28 18:01 UTC

This package is auto-updated.

Last update: 2024-09-30 02:10:35 UTC


README

CI

Eloquent flat file driver,基于 Sushi 🍣

需求

PHP 8.1.4 或更高版本,Laravel 9+

向下兼容性已经到来。

安装

您可以通过 composer 安装此包。

composer require authanram/laravel-flatfile

默认情况下,此包写入的所有文件都将位于 storage_path('app/flatfile')

发布 包配置

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

快速检查配置文件 config/flatfile.php 是一个好主意。

使用示例

以下是一个如何以非常基本的方式使用的示例

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',
    ];
}

代码的其它地方

use App\Models\Post;

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

这将把以下内容存储到 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
}

此包还提供第二个序列化器,支持 yaml,这将导致以下文件内容存储在 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 关系目前不支持

    为了方便 many-to-many 关系,请退回到 Eloquent 支持的常规 DBMS,或者您可以自由地创建 pull request

贡献

请参阅 贡献指南 以获取详细信息。

安全漏洞

请查看 我们的安全策略 了解如何报告安全漏洞。

致谢

特别感谢 Caleb Porzio,底层包 Sushi 🍣 的作者。

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件