authanram / laravel-flatfile
正在开发中
1.0.2
2022-06-28 18:01 UTC
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-09-30 02:10:35 UTC
README
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)。有关更多信息,请参阅 许可文件。