PHP code example of pion / laravel-support-eloquent

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

    

pion / laravel-support-eloquent example snippets


public $cleanAttributes = [
    "name"
];

public $dontCleanAttributes = [
    "name"
];

public $nullEmptyAttributes = [
    "name"
];

public $dontNullEmptyAttributes = [
    "name"
];

public $dateAttributes = ['custom_date'];

public $dateFormats = [
    'born' => 'Y-m-d'
];

/**
 * Set a given attribute on the model.
 *
 * @param  string $key
 * @param  mixed  $value
 */
public function setAttribute($key, $value)
{
    parent::setAttribute($key, alter_attribute_value($key, $value, $this, [
        'tryToCleanAttributeValue',
        'tryToNullAttributeValue'
    ]));
}

protected $relationAliases = [
    "activity_type" => "type"
];

Model::modelJoin("type")->get()

Model::modelJoin("type", ["name", "id", "color"])->get();

$model->type->color

Model::modelJoin("type", ["name", "id", "color"], "inner")->get();

modelJoin($query, $relation_name, $operatorOrColumns = '=', $type = 'left', $where = false, $columns = array())

joinWithSelect($query, $table, $one, $operatorOrColumns, $two, $type = "left", $where = false, $columns = array())
    
$count = $model->relationCountWithWhere("user_permission", "user_id", $user, "App\\Models\\User");

$model->user_permission_{ForeignKey}_{userIdValueForWhere} which will the object of User model with count attribute.

$index = "user_permission";
$model->relationCountWithWhere($index, "user_id", $user, "App\\Models\\User");

$model->relationCount("user", "App\\Models\\User")