PHP code example of rexshijaku / sql-to-laravel-builder

1. Go to this page and download the library: Download rexshijaku/sql-to-laravel-builder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rexshijaku / sql-to-laravel-builder example snippets




use RexShijaku\SQLToLaravelBuilder\SQLToLaravelBuilder;

ravelBuilder($options);

$sql = "SELECT COUNT(*) FROM members";
echo $converter->convert($sql);

DB::table('members')->count();

$sql = "SELECT
                department_id,
                count(*) 
            FROM
                members
                LEFT JOIN details AS d ON d.member_id = members.member_id 
            WHERE
                ( age = 25 OR ( salary = 2000 AND gender = 'm' ) ) 
                AND id > 15 
            GROUP BY
                department_id 
            HAVING
                height > 1.60";
echo $converter->convert($sql);

DB::table('members')
    ->select('department_id', DB::raw('count(*)'))
    ->leftJoin('details AS d', 'd.member_id', '=', 'members.member_id')
    ->where(function ($query) {
        $query->where('age', '=', 25)
              ->orWhere(function ($query) {
                            $query->where('salary', '=', 2000)
                                  ->where('gender', '=', 'm');
        });
    })
    ->where('id', '>', 15)
    ->groupBy('department_id')
    ->having('height', '>', 1.60)
    ->get();