manojkiran/querybuilderhelper

Some of the useful Helpers and macros for Laravel Query Builder.

0.1.2 2019-03-18 09:12 UTC

README

Packagist License Latest Stable Version Latest Unstable Version License Total Downloads Laravel5.8

Some of the useful Helpers for the laravel query builder.

Installation

Via Composer

$ composer require manojkiran/querybuilderhelper

HOW IT WORKS

It is working like the scopes in the laravel with the scopes of the Model Scopes

  • scopeToSqlWithValues AS toSqlWithValues

Usage

In Your Model add the following lines to list of namespaces

use Illuminate\Database\Eloquent\Model;
use manojkiran\QueryBuilderHelper\QueryBuilderHelperTrait;

class YourModel extends Model
{
    use QueryBuilderHelperTrait;
}

In Your Controller You can Use

namespace App\Http\Controllers;

use App\User;

class HomeController extends Controller
{

    /**
     * Show the user list.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
    
        $builderQuery = User::where('name','=','jhon')->where('email','=','test@test.com');
        $toSqlMethod = $builderQuery->toSql();
        $toSqlWithValuesScope = $builderQuery->toSqlWithValues();
        
        
        dd($toSqlMethod,$toSqlWithValuesScope);
        
        Now the Dumped result will be
        
        For toSql() method
        
        select * from `users` where `name` = ? and `email` = ?
        
        For toSqlWithValues() method
        
        select * from `users` where `name` = 'jhon' and `email` = 'test@test.com'

    }

As You can see the all the values with the bindings are displayed in toSqlWithValues()

displayes the sql query with values without trimming

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email manojkiran10031998@gmail.com instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.