alvarofpp/expand-database

该软件包已被废弃,不再维护。未建议替代软件包。

一个使数据库更强大的软件包

1.2.0 2020-05-28 21:54 UTC

This package is auto-updated.

Last update: 2024-02-29 04:18:36 UTC


README

Packagist Version License

一个使数据库更强大的软件包。

内容

安装

通过composer安装

composer require alvarofpp/expand-database

Laravel使用软件包自动发现,因此不需要您手动添加ServiceProvider。但如果不使用自动发现,请打开config/app.php文件,并添加以下行以注册服务提供者

'providers' => [
    // ...

    Alvarofpp\ExpandDatabase\ExpandDatabaseServiceProvider::class,

    // ...
],

用法

该软件包目前包含

  • 表注释(MySQL/PostgreSQL)。
  • 绑定到SQL。

表注释

向表添加注释(MySQL/PostgreSQL)。在Blueprint对象中使用comment方法,例如

<?php
Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->string('email')->unique();
    $table->timestamp('email_verified_at')->nullable();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();

    $table->comment('Stores users');
});

要删除表注释,使用removeComment()方法

<?php
Schema::table('users', function (Blueprint $table) {
    $table->removeComment();
});

绑定到SQL

您可以使用toSqlWithBindings()方法打印带有绑定的SQL(显然)。请参见以下示例

<?php
$query = Course::where('price', '>', $request->price)
    ->where('rating', '>=', $request->min_rating)
    ->where('rating', '<=', $request->max_rating);

dd($query->toSql(), $query->toSqlWithBindings());

// toSql(): "select * from "courses" where "price" > ? and "rating" >= ? and "rating" <= ?"
// toSqlWithBindings(): "select * from "courses" where "price" > 100.0 and "rating" >= 4.3 and "rating" <= 5.0"

贡献

欢迎贡献。Fork、改进并提交拉取请求。对于错误、改进想法或其他,请创建一个问题