doushang9172 2019-04-11 19:31
浏览 23

如何使用select 2(插件)手动和从数据库动态保存标签

i can store tags from database, but when i try to input tags manually, i can't do that because the new tag not store in database.

here is what can i do so far

my controller to store data

 $data = $this->handleRequest($request);//for handle image request
 $newPost = $request->user()->posts()->create($data);
 $newPost->tags()->sync($request->tags, false);

my form

{!!Form::select('Tags',$tags->pluck('name','id')->all(),null,array(
                'multiple' => 'multiple',
                'class'    => 'form-control select2-multi',
                'name'     => 'tags[]'))
            !!}

and script

$('.select2-multi').select2({
tags: true,
tokenSeparators: [","]
}).
    val({!! json_encode($post->tags()->pluck('id')->toArray())!!}).trigger('change');
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统