2016-09-20 3 views
0

나는 laravel 5.3 응용 프로그램을 가지고 내가 가진 새 게시물 페이지가 : 컨트롤러 경우에 선택 2 https://select2.github.io/선택 2 및 laravel 5.3 형태

태그 모델

<?php 

namespace App\Models; 

use Eloquent as Model; 
use Illuminate\Database\Eloquent\SoftDeletes; 

/** 
* Class tag 
* @package App\Models 
* @version September 20, 2016, 5:31 am UTC 
*/ 
class tag extends Model 
{ 
    use SoftDeletes; 

    public $table = 'tags'; 


    protected $dates = ['deleted_at']; 


    public $fillable = [ 
     'name', 
     'id' 
    ]; 

    /** 
    * The attributes that should be casted to native types. 
    * 
    * @var array 
    */ 
    protected $casts = [ 
     'name' => 'string' 
    ]; 

    /** 
    * Validation rules 
    * 
    * @var array 
    */ 
    public static $rules = [ 

    ]; 
    public function post() 
    { 
     return $this->belongsTo('App\Models\Post'); 
    } 
    public function movie() 
    { 
     return $this->belongsTo('App\Models\Movies'); 
    } 


} 

를 사용

<div class="form-group col-sm-12"> 
    <label for="tags"> Select Tags</label> 
    <select class="custom-select form-control" name="tags" id="tag-select" multiple="multiple"> 
    @foreach($tags as $tag) 
     <option value="{{$tag->id}}">{{$tag->name}} </option> 
    @endforeach  
    </select> 
</div> 

i 나는 내가 마지막으로 클릭 한 태그의 값만 가져옵니다.


입력 할 때마다 값을 전달하고 컨트롤러에서 가져 오는 방법을 알려주십시오.

기타 문의 사항이 있으면 알려주세요.

감사

+0

나는 – Nour

답변

0

blade templating를 사용하지 않는?

{{ Form::select('tags', \App\tags::all()->pluck('name', 'id')->toArray(), null,['class'=>'select2']) }} 

당신의 div 내부 : 은과 같이 그것을 발견되지 `칼럼 :

<div class="form-group col-sm-12"> 

{{ Form::label('Select Tags', null, ['class' => 'control-label']) }} 
{{ Form::select('tags[]', \App\tags::all()->pluck('name', 'id')->toArray(), null,['class'=>'select2']) }} 

</div> 
+0

이 좋아 내가 그것을 시도 확인해하지만 난 오류가 제발 대답을 업데이 트했습니다 : 1054 알 수없는 열 tags.post_id 'where 절에서 (SQL : select * from tags where tag.post_id = 1, tags.post_id는 null이 아니고 tags.deleted_at는 null입니다.)' 어디에서 블레이드가 post_id를 호출합니까? – Krubbit

+0

'태그'모델을 보여줄 수 있습니까? – Nour

+0

게시물을 업데이트했습니다. – Krubbit