Emmanuelpcg laravel-basics
Description
Package with basic starter features for Laravel.
Install
composer require emmanuelpcg/laravel-basics
If Builder
Creates an eloquent builder that checks a condition to be executed
In app/providers/AppServiceProvider.php
add:
public function register()
{
BuilderQueries::builderIf();
}
without operator param:
$cars = Cars::where('color', 'red')
->if(auth()->check(), 'color', 'blue')
->get();
with operator param:
$cars = Cars::where('color', 'red')
->if(auth()->check(), 'color', '!=', 'red')
->get();
Constants
creates an object with extra features of the constants:
class CarTypes extends Constants
{
const MUSCLE = 1;
const SPORT = 2;
}
CarTypes::getConstants();
/**
[
"MUSCLE" => 1,
"SPORT" => 2
]
*/
CarTypes::getValues();
/** [1, 2] */
CarTypes::toSelectOptions();
/**
[
[
'value' => 1,
'text' => "MUSCLE"
],
[
'value' => 2,
'text' => "SPORT"
]
]
*/