PHPackages                             webdevjohn/selectboxes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. webdevjohn/selectboxes

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

webdevjohn/selectboxes
======================

Elegant creation of Selectboxes for use within HTML forms.

v1.0.3(1y ago)039MITPHPPHP ^8.0

Since Jun 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/webdevjohn/selectboxes)[ Packagist](https://packagist.org/packages/webdevjohn/selectboxes)[ RSS](/packages/webdevjohn-selectboxes/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (4)Dependencies (1)Versions (6)Used By (0)

Select Boxes
============

[](#select-boxes)

Introduction
------------

[](#introduction)

The Select Boxes package was created to provide an easy way to create the data used in select boxes on HTML forms. The package also helps dry-up your code by encapsulating select box data within dedicated re-usable classes.

### Example Problem

[](#example-problem)

It can be a pain when dealing with forms that require multiple select boxes, as the select boxes that are defined in the `create()` method also have to be re-defined within the `edit()` method of a controller. With the example below, you would also need to import 5 eloquent models: `Artist, Genre, Label, Format, Tag`. This starts to become messey.

```
use App\Models\Artist;
use App\Models\Format;
use App\Models\Genre;
use App\Models\Label;
use App\Models\Tag;

public function create()
{
    return View('cms.basedata.tracks.create', [
        'selectBoxes' => [

            'artistList' => Artist::orderBy('artist_name')
                ->pluck('artist_name', 'id')
                ->toArray(),

            'genreList' => array_merge(
                [0 => 'Please Select...'],
                Genre::orderBy('genre')->pluck('genre', 'id')->toArray()
            ),

            'labelList' => array_merge(
                [0 => 'Please Select...'],
                Label::orderBy('label')->pluck('label', 'id')->toArray()
            ),

            'formatList' => array_merge(
                [0 => 'Please Select...'],
                Format::orderBy('format')->pluck('format', 'id')->toArray(),
            ),

            'tagList' => Tag::orderBy('tag')->pluck('tag', 'id')
        ]
    ]);
}

```

### Example Solution

[](#example-solution)

The above example can be refactored to the following when using the Select Boxes package:

```
// The model import use statements are no longer needed.

public function create()
{
    return View('cms.basedata.tracks.create', [
        'selectBoxes' => $this->selectBoxes->get(),
    ]);
}

```

Installation
------------

[](#installation)

The package can be installed via composer using the following command:

```
composer require webdevjohn/selectboxes

```

Usage
-----

[](#usage)

You can create a select box group, or use the `SelectBoxService` directly.

### Creating a Select Box Group

[](#creating-a-select-box-group)

Create a select box group when multiple select boxes are needed on a form. This can help DRY up your code, as the select box group can be re-used when creating and updating records (e.g. the `create()` and `edit()` methods of a controller).

Run the following artisan command to create a select box group:

```
php artisan group:make {name}

```

By default, the newly created group will created in:

```
App\Services\SelectBoxes\Groups

```

You can override the default namespace by specifying an optional 2nd argument when creating a group:

```
php artisan group:make {name} {namespace}

```

#### Defining Select Boxes

[](#defining-select-boxes)

```
namespace App\Services\SelectBoxes\Groups;

use App\Models\Artist;
use App\Models\Format;
use App\Models\Genre;
use App\Models\Label;
use App\Models\Tag;
use Webdevjohn\SelectBoxes\SelectBoxService;

class DemoSelectBoxGroup extends SelectBoxService
{
    public function get(): array
    {
         return  [
            'artistList' => $this->createFrom(Artist::class)
                ->display('artist_name')
                ->orderBy('artist_name')
                ->asArray(placeHolder: false),

            'genreList' => $this->createFrom(Genre::class)
                ->display('genre')
                ->orderBy('genre')
                ->asArray(),

            'labelList' => $this->createFrom(Label::class)
                ->display('label')
                ->orderBy('label')
                ->asArray(),

            'formatList' => $this->createFrom(Format::class)
                ->display('format')
                ->orderBy('format')
                ->asArray(),

            'tagList' => $this->createFrom(Tag::class)
                ->display('tag')
                ->orderBy('tag')
                ->asArray(placeHolder: false),
        ];
    }
}

```

#### Available Methods

[](#available-methods)

MethodMethod TypeArgumentsReturnscreateFrom()Mandatory$model **string** - fully qualified class nameSelectBoxServicedisplay()Mandatory$optionText **string** - the text that is displayed for a select box option
 $optionValue **string** - the value of a select box option (default = "**id**")SelectBoxServicewhere()Optional$column **string** - name of the column to filter
 $operator **string** - the comparison operator
 $value **string** - the valueSelectBoxServiceorderBy()Optional$orderBy **string** - name of the column to order by
 $sortOrder **string** - sort order (default = "**desc**")SelectBoxServiceasArray()Optional\*$placeHolder **bool** - include a placeholder (default = "**true**")
 $placeHolderText **string** - (default = "**Please Select....**")ArrayasJson()Optional\*$placeHolder **bool** - include a placeholder (default = "**true**")
 $placeHolderText **string** - (default = "**Please Select....**")String (JSON)\*note. either `asArray()` or `asJson()` must be called in order to return results.

### Using a Select Box Group

[](#using-a-select-box-group)

You can use constructor or method injection to inject a Select Box Group.

```
public function __construct(
    protected DemoSelectBoxGroup $selectBoxes
) {}

```

Then use the `get()` method on the `$selectBoxes` instance variable to create the select boxes.

```
public function create()
{
    return View('cms.basedata.tracks.create', [
        'selectBoxes' => $this->selectBoxes->get(),
    ]);
}

```

This will push the data to the view in the following format:

```
array:1 [▼
  "selectBoxes" => array:5 [▼
    "artistList" => array:1378 [▶]
    "genreList" => array:12 [▶]
    "labelList" => array:484 [▶]
    "formatList" => array:4 [▶]
    "tagList" => array:26 [▶]
  ]
]

```

##### Acessing Select Boxes Within a Blade File

[](#acessing-select-boxes-within-a-blade-file)

```
Genre:

    @foreach($selectBoxes['genreList'] as $key => $value)
        {{ $value }}
    @endforeach

```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~315 days

Total

5

Last Release

536d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8057438?v=4)[webdevjohn](/maintainers/webdevjohn)[@webdevjohn](https://github.com/webdevjohn)

---

Top Contributors

[![webdevjohn](https://avatars.githubusercontent.com/u/8057438?v=4)](https://github.com/webdevjohn "webdevjohn (10 commits)")

---

Tags

laravelSelectBoxes

### Embed Badge

![Health badge](/badges/webdevjohn-selectboxes/health.svg)

```
[![Health](https://phpackages.com/badges/webdevjohn-selectboxes/health.svg)](https://phpackages.com/packages/webdevjohn-selectboxes)
```

###  Alternatives

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[nickurt/laravel-akismet

Akismet for Laravel 11.x/12.x/13.x

97139.6k2](/packages/nickurt-laravel-akismet)[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)[sbine/route-viewer

A Laravel Nova tool to view your registered routes.

57215.9k](/packages/sbine-route-viewer)[forxer/laravel-gravatar

A library providing easy gravatar integration in a Laravel project.

4235.6k](/packages/forxer-laravel-gravatar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
