allenjd3/laravel-flywheel

laravel-flywheel 包的 laravel 封装

v0.0.3 2017-08-12 01:17 UTC

This package is not auto-updated.

Last update: 2024-09-29 03:52:42 UTC


README

这是 Jamesmoss/flywheel 包的封装类。

用于平面文件文档的 laravel 门面

这是一个可以与默认的 Laravel 数据库结构一起使用的门面。由于这不会覆盖 Laravel 的核心数据库功能,所以您可以同时使用两者。

安装

composer require allenjd3\laravel-flywheel

然后,将以下内容添加到您的 config/app 文件中的应用程序提供者部分

'providers' => [
    ...
        /*
        * Package Service Providers...
        */
        Allenjd3\Flywheel\FlywheelServiceProvider::class,
    ...
]

如果您想使用 Facade,请将此添加到您的别名数组中

'aliases' => [
    ... 
    'Flywheel' => Allenjd3\Flywheel\facades\Flywheel::class,
    ...

]

方法

配置

如果您想更改表名或存储路径,此方法是非必需的

示例- (可选)

$flywheel = Flywheel::config($name, $path);
$flywheel->findAll();

创建

此方法创建一个新文档并将其保存到您的路径。在运行此操作之前,您可以在请求上使用 Laravel 验证。

$id = Flywheel::create($array)

更新 / findById

此方法更新一个帖子。在更新之前,您必须通过 ID 找到帖子。

$doc = Flywheel::findById($id);
$doc->param = "new value";
Flywheel::update($doc);

findAll

此方法查找给定配置路径内的所有文档

$docs = Flywheel::findAll();

删除

此方法删除与给定 ID 匹配的帖子。

Flywheel::delete($id)

Where / get

此方法返回一个可链式的查询对象

$docs = Flywheel::where('title', '==', 'Shiver Me Timbers')->get();

get 结束查询并执行结果。

limit, orderBy, andWhere

$docs = Flywheel::limit($count, $offset)->get();
$docs = Flywheel::orderBy('fieldname ASC|DESC')->get();

andWhere 是附加 where 查询的封装。

所有类型的查询(where、limit、orderby、andWhere)都可以在调用 get 之前进行链式调用。例如-

$docs = Flywheel::where('title','==','Most Excellent')
                ->limit(5,2)
                ->orderBy('title ASC')
                ->get();

第一个

如果您只想返回单个文档,则可以运行 first 而不是 get

$doc = Flywheel::where('title', '==', 'Most Excellent')->first();

所有返回值都可以返回,并将返回 JSON 字符串。

return $docs;

如果您想返回一个带有 application/json 头的 Laravel 响应对象,则可以运行

return $docs->toJson();

return $docs->toArray();

当然,您也可以始终将变量传递到 Blade 模板中

return view('template.name', compact('docs'));

发现错误或想要一个功能?

发送 pull request!