2017 © Pedro Peláez
 

library bullets

Add bullet points to Laravel 5.1 Eloquent models.

image

craigzearfoss/bullets

Add bullet points to Laravel 5.1 Eloquent models.

  • Sunday, January 15, 2017
  • by craigzearfoss
  • Repository
  • 1 Watchers
  • 0 Stars
  • 33 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Bullets for Laravel 5

This package allows you to attach bullet points to an Eloquent model in Laravel 5., (*1)

Composer Install

It can be found on Packagist. The recommended way is through composer., (*2)

Edit composer.json and add:, (*3)

{
    "require": {
        "craigzearfoss/bullets": "dev-master"
    }
}

And install dependencies:, (*4)

$ composer update

If you do not have Composer installed, run these two commands:, (*5)

$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install

Install and then Run the migrations

Find the providers array key in config/app.php and register the Bullets Service Provider., (*6)

'providers' => array(
    // ...

    Craigzearfoss\Bullets\BulletsServiceProvider::class,
)

Run the migration to create the bullets table., (*7)

php artisan vendor:publish --provider="Craigzearfoss\Bullets\Providers\BulletsServiceProvider"
php artisan migrate

Configuration

In your model add the BulletableTrait., (*8)

<?php

// ...
use Craigzearfoss\Bullets\BulletableTrait;

class MyModel extends Model
{
    use BulletableTrait;

Usage

To fetch the bullets for your model:, (*9)

$bullets = $myModel->bullets()->get();

To sync the bullets for your model when storing or updating:, (*10)

$myModel->syncBullets(isset($data['bullet_list']) ? $data['bullet_list'] : []);

To add the bullets for your model to you forms blade templates:, (*11)

  1. Add the form select element.
<div class="form-group">
    {!! Form::label('bullet_list', 'Bullet Points:') !!}
   {!! Form::select('bullet_list[]', $myModel->bullets()->lists('comment', 'comment')->toArray(), array_keys($myModel->bullets()->lists('comment', 'comment')->toArray()), ['id' => 'bullet_list', 'class' => 'form-control select2-bullet-list', 'multiple']) !!}
</div>
  1. Add select.js to your layout.
<script type="text/javascript" src="js/select2.min.js"></script>
  1. Add the following to your css for the form element. This makes the bullet select list items have a width of 100%.
.select2-bullet-list + .select2-container--default .select2-selection--multiple .select2-selection__choice {
    width: 100%;
}
        ```

4. Add the following JavaScript to the form page.
```javascript
<script type="text/javascript">
    $("#bullet_list").select2({
        placeholder: "Add Bullet Points",
        tags: true,
        tokenSeparators: ["\n"],
        maximumSelectionLength: 255
    });
</script>
  • To display the bullets for your model in a blade template:
@if (!empty($bullets))
    <ul>
        @foreach($bullets as $bullet)
            <li>{{ $bullet->comment }}</li>
        @endforeach
    </ul>
@endif

Changelog

See the CHANGELOG file, (*12)

Support

Please open an issue on GitHub, (*13)

Contributor Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms., (*14)

License

Bullets is released under the MIT License. See the bundled LICENSE file for details., (*15)

The Versions

15/01 2017

dev-master

9999999-dev

Add bullet points to Laravel 5.1 Eloquent models.

  Sources   Download

MIT License

The Requires

 

laravel php tags craigzearfoss

27/04 2016

1.0.0

1.0.0.0

Add bullet points to Laravel 5.1 Eloquent models.

  Sources   Download

MIT License

The Requires

 

laravel php tags craigzearfoss