PHP code example of fatihirday / eloquent

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

    

fatihirday / eloquent example snippets


'providers' => [
    // ...
    Fatihirday\Eloquent\EloquentServiceProvedir::class,
],

Model::ifNull('column', 'value', 'responseName');
// or
Model::query()->ifNull('column', 'value', 'responseName');

Model::ifCount('column', 12, 'responseName');
// or
Model::ifCount('column', '!=', 'value', 'responseName');

Model::ifSum('column', '!=', 'value', 'responseName');
// or
Model::ifSum('column', '=', 'value', 'sumColumn', 'responseName');

Model::sumColumn('column'); // sum(column) as column
// or
Model::sumColumn('column', 'responseName'); // sum(column) as responseName

Model::countColumn('column'); // count(column) as column
// or
Model::countColumn('column', 'responseName'); // count(column) as responseName

Model::concat(['name', 'id'], 'responseName') // nameid
// or
Model::concat(['name', 'id'], 'responseName', '-') // name-id

Model::caseWhen([
    'updated_at > created_at' => 'updated_at', // When Then
    'deleted_at > created_at' => 'deleted_at', // When Then
    'created_at', // Else
], 'responseName')

use Fatihirday\Eloquent\Libraries\Enums\Like;

Model::whereLike('columnName', 'value', Like::FIRST); 
// WHERE columnName like '%value'

Model::whereLike('columnName', 'value', Like::MIDDLE); 
// WHERE columnName like '%value%'

Model::whereLike('columnName', 'value', Like::LAST); 
// WHERE columnName like 'value%'

use Fatihirday\Eloquent\Libraries\Enums\Like;

Model::where('id', '>', 1)->orWhereLike('columnName', 'value', Like::FIRST); 
// WHERE id > 1 or columnName like '%value'

Model::where('id', '>', 1)->orWhereLike('columnName', 'value', Like::MIDDLE); 
// WHERE id > 1 or columnName like '%value%'

Model::where('id', '>', 1)->orWhereLike('columnName', 'value', Like::LAST); 
// WHERE id > 1 or columnName like 'value%'

echo Model::where('name', 'value')->getSql();
// select * from `table_name` where `name` = 'fatih'

Model::where('name', 'value')->dumpSql();
// select * from `table_name` where `name` = 'fatih'

Model::where('name', 'value')->ddSql();
// select * from `table_name` where `name` = 'fatih'