LaravelPackages.net
Acme Inc.
Toggle sidebar
binarycabin/options

Class-based select options for Laravel

1.029
1
1.0.0
About binarycabin/options

binarycabin/options is a Laravel package for class-based select options for laravel. It currently has 1 GitHub stars and 1.029 downloads on Packagist (latest version 1.0.0). Install it with composer require binarycabin/options. Discover more Laravel packages by binarycabin or browse all Laravel packages to compare alternatives.

Last updated

Options

Build Status StyleCI Latest Stable Version Total Downloads

Class-based select options for Laravel.

This package makes it easy to store a static list of array items. This is useful in form select-list building.

Installation

composer require binarycabin/options

Usage

Generate Permissions

php artisan make:option CLASSNAME

ie:

php artisan make:option County

This will create a new file located at: /app/Options/Country.php

Edit your array

In your generated option file, edit the array in the getArray method to include the available option items:

public function getArray(){
  return [
    'US' => 'United States of America',
    'CA' => 'Canada',
  ];
}

Display the option

foreach(\App\Options\County::get('---') as $optionKey => $optionValue)
{
  echo '<option value="{{ $optionKey }}">{{ $optionValue }}</option>'
}

or using something like anahkiasen/former:

{!! Former::select()->options(\App\Options\County::get('---')) !!}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Star History Chart