PHP code example of schrosis / blade-sql

1. Go to this page and download the library: Download schrosis/blade-sql 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/ */

    

schrosis / blade-sql example snippets


Schrosis\BladeSQL\Providers\BladeSQLServiceProvider::class,

'BladeSQL' => Schrosis\BladeSQL\Facades\BladeSQL::class,

use Schrosis\BladeSQL\Facades\BladeSQL;

$user = BladeSQL::select('users.select', ['id' => 1])->first();
// (object)[
//     'id' => '1',
//     'name' => 'examplename'
// ]

use Schrosis\BladeSQL\Facades\BladeSQL;
use App\Moldes\Todo;
use App\Entities\YourTodoEntity;

$stdClassCollection = BladeSQL::select('todos.select');

// to model collection
$modelCollection = $stdClassCollection
    ->model(Todo::class); // or model(new Todo())

// to entity collection
$entityCollection = $stdClassCollection
    ->entity(YourTodoEntity::class);

class YourTodoEntity
{
    private $id;
    private $contents;
    private $finished_at;
    private $created_at;

    public static fromArray(array $data)
    {
        // some code
    }
}

$insertedRowNum = BladeSQL::insert('todos.new', [
    'contents' => 'Implement that function',
]);

$updatedRowNum = BladeSQL::update('todos.done', [
    'id' => 1,
    'finished_at' => \Carbon\Carbon::now(),
]);

$deletedRowNum = BladeSQL::delete('todos.delete', [
    'id' => 1,
]);

// Same string value as the argument of DB::connection()
BladeSQL::setConnection('mysql::write')->update('users.change-password', $queryParams);
// or
// Accept ConnectionInterface
$connection = DB::connection('mysql::write');
BladeSQL::setConnection($connection)->update('users.change-password', $queryParams);

php artisan vendor:publish --provider="Schrosis\BladeSQL\Providers\BladeSQLServiceProvider"

LIKE ? ESCAPE '\'