samedi 26 décembre 2015

tagging a new model - preloaded array produces an error - Laravel

I use this package as an egine for my tagging functionality: http://ift.tt/1Pp0NFy

Now, when creating new model, in my controller I declare a variable with all available tags:

        $tags = array('' => 'Enter your tags...') + Tag::orderBy('name', 'asc')->lists('name', 'name')->all();

Then, in my create view I define this field:

    {!! Form::select('Tags[]', $tags, Input::old('Tags') ,['multiple' => 'multiple', 'data-tags' => 'true', 'data-token-separators' => "[',', ' ']", 'data-placeholder' => "{$tags['']}", 'class' => '']) !!}

Problem

when I write a first tag, say politics, two tags appear in the window: the politics and the empty tag defined in the controller '' => 'Enter your tags...' I need to remove the tag manually each time I use the form.

When I remove the array('' => 'Enter your tags...') + part of my variable, I get error

`Undefined index: (View: resources/views/events/create.blade.php)`

My question

how to make the select box work properly. Thx.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire