sukohi/broom
Larablocks Analysis
sukohi/broom works with Laravel 5 (latest release 3.0.3, Sep 11, 2019), which reached end of life: no more fixes, even for security.
Laravel 4 in earlier releases.
Recommendation checks
Not advisedNot advised: no release or commit in over 2 years.
- No release or commit in over 2 years
- Supports only Laravel 5, past end of life
- No release in the last 12 months (last: Sep 11, 2019)
- 0 downloads a month (needs 10,000)
- 7 GitHub stars (needs 100)
State
Likely abandoned- No release or commit in over 2 years.
- Last stable release: Sep 11, 2019.
- No releases in the last 12 months.
- First released: Aug 6, 2015.
- 0 open issues on GitHub.
Data from Packagist and GitHub, checked by Larablocks on Nov 27, 2026.
| Install | |
|---|---|
composer require sukohi/broom |
|
| Latest Version: | 3.0.3 |
| Laravel: | 5 |
| Older releases: | 4 |
| License: | MIT |
| Last Updated: | Sep 11, 2019 |
| Links: | GitHub · Packagist |
Broom
A PHP package mainly developed for Laravel to manage option values using Trait.
(This packages is maintained under L54)
Installation
Execute composer command.
composer require sukohi/broom:3.*
Preparation
Simple Way
In your model, set BroomTrait and add a method named "options" which return values you want.
<?php
namespace App;
use Sukohi\Broom\BroomTrait;
class Color {
use BroomTrait;
public static function options() {
return [
'1' => 'Red',
'2' => 'Blue',
'3' => 'Green'
];
}
Or you can simply prepare by setting $option property like so if your model extends Illuminate\Database\Eloquent\Model.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Sukohi\Broom\BroomTrait;
class Color extends Model {
use BroomTrait;
protected $option = ['id' => 'name']; // or 'name';
Now you also can call the next methods.
- optionValue()
- optionValues()
- optionKey()
- optionKeys()
- optionRandom()
- optionKeyRandom()
- optionHasKey()
- optionHasValue()
- optionsWithTitle()
Usage
Options
$colors = \App\Color::options();
print_r($colors);
/* Output
Array
(
[1] => Red
[2] => Blue
[3] => Green
)
*/
Note: You will get Collection when you set $option.
Value
echo \App\Color::optionValue(2); // Blue
or You can set default value.
echo \App\Color::optionValue(5, 'Default'); // Default
Key
echo \App\Color::optionKey('Green'); // 3
Values
$values = \App\Color::optionValues();
print_r($values);
/* Output
Array
(
[0] => Red
[1] => Blue
[2] => Green
)
*/
You also can filter the values by setting ids.
$values = \App\Color::optionValues([2, 3]);
print_r($values);
/* Output
Array
(
[0] => Blue
[1] => Green
)
*/
Keys
$keys = \App\Color::optionKeys();
print_r($keys);
/* Output
Array
(
[0] => 1
[1] => 2
[2] => 3
)
*/
Random
echo \App\Color::optionRandom(); // Blue
$options = \App\Color::optionRandom(2); // If you set a numeric argument, you can get array values.
print_r($options);
/* Output
Array
(
[0] => Blue
[1] => Green
)
*/
Key Random
echo \App\Color::optionKeyRandom(); // 2
$options = \App\Color::optionKeyRandom(2);
print_r($options);
/* Output
Array
(
[0] => 1
[1] => 3
)
*/
Has Key
$key = 3;
if(\App\Color::optionHasKey($key)) {
echo 'Has key!';
}
Has Value
$value = 'Red';
if(\App\Color::optionHasValue($value)) {
echo 'Has value!';
}
With Default Title
$options = \App\Color::optionsWithTitle('Pick one');
/* Output
Array
(
[] => Pick one
[1] => Red
[2] => Blue
[3] => Green
)
*/
$options = \App\Color::optionsWithTitle('Pick one', '-99');
/* Output
Array
(
[-99] => Pick one
[1] => Red
[2] => Blue
[3] => Green
)
*/
optionIs
$key = '1';
if(\App\Item::optionIs('Item - 1', $key)) {
echo 'True!';
}
optionsList
$list = \App\Item::optionsList(); // Default: $id_key => 'id', $value_key => 'text'
// or
$id_key = 'id';
$value_key = 'text';
$list = \App\Item::optionsList($id_key, $value_key);
/*
Array
(
[0] => Array
(
[id] => 1
[text] => Red
)
[1] => Array
(
[id] => 2
[text] => Blue
)
[2] => Array
(
[id] => 3
[text] => Green
)
)
*/
Cache
$option_cache allows you to use cache for quick access.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Sukohi\Broom\BroomTrait;
class Color extends Model {
use BroomTrait;
protected $option_cache = true;
then use forgetCache() for deleting cache;
Customized Method Name
You also can use customized method name like "redOptions".;
use Sukohi\Broom\BroomTrait;
class Color {
use BroomTrait;
public static function redOptions() {
return [
'1' => 'cherry',
'2' => 'rose',
'3' => 'crimson'
];
}
Now you can call redOptionValue(), redOptionValues(), redOptionKey(), redOptionKeys(), redOptionRandom(), redOptionKeyRandom(), redOptionHasKey(), redOptionHasValue() and redOptionsWithTitle().
License
This package is licensed under the MIT License.
Copyright 2015 Sukohi Kuhoh
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 3.0.3 | ~5.0 | MIT | ||
| 3.0.2 | ~5.0 | MIT | ||
| 3.0.1 | ~5.0 | MIT | ||
| 3.0.0 | ~5.0 | MIT | ||
| 2.0.8 | ~5.0 | MIT | ||
| 2.0.7 | ~5.0 | MIT | ||
| 2.0.6 | ~5.0 | MIT | ||
| 2.0.5 | ~5.0 | MIT | ||
| 2.0.4 | ~5.0 | MIT | ||
| 2.0.3 | ~5.0 | MIT | ||
| 2.0.2 | ~5.0 | MIT | ||
| 2.0.1 | ~5.0 | MIT | ||
| 2.0.0 | ~5.0 | MIT | ||
| 1.0.1 | >=5.4.0 | 4.2.* | MIT | |
| 1.0.0 | >=5.4.0 | 4.2.* | MIT |