alvarofpp / expand-database
A package to make your database more powerful
Requires
- php: >=7.2.0
Requires (Dev)
- laravel/laravel: >=6.0
This package is auto-updated.
Last update: 2024-02-29 04:18:36 UTC
README
A package to make your database more powerful.
Contents
Install
Install via composer:
composer require alvarofpp/expand-database
Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
But if you don't use auto-discovery, open the config/app.php
file and add the following line to register the service provider:
'providers' => [ // ... Alvarofpp\ExpandDatabase\ExpandDatabaseServiceProvider::class, // ... ],
Usage
This package currently contains:
- Table comment (MySQL/PostgreSQL).
- To Sql with bindings.
Table comment
Add a comment to a table (MySQL/PostgreSQL).
Use the method comment
in your Blueprint object, like:
<?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'); });
To remove the table comment, use removeComment()
method:
<?php Schema::table('users', function (Blueprint $table) { $table->removeComment(); });
To Sql with bindings
You can use the toSqlWithBindings()
method to print your SQL with bindings (obviously). See this example:
<?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"
Contributing
Contributions are more than welcome. Fork, improve and make a pull request. For bugs, ideas for improvement or other, please create an issue.