2016-01-02 247 views
0

我在將數據保存到laravel 5中的m:n表格佈局時遇到了問題。我有table appliance和table documentations,其中數據透視表是documentation_appliance。Laravel 5.2將數據保存到m:n表

型號有:

class Appliances extends Model 
    {  
     public function documentations() 
     { 
      return $this->belongsToMany('documentations'); 
     } 

    } 

class Documentation extends Model 
{ 
public function appliances() 
{ 
    return $this->belongsToMany('appliances'); 
} 
} 

現在,我嘗試將數據表保存在我的控制器

public function store(Request $request) 
{ 
    $this->validate($request, [ 
     'name' => 'required|max:255', 
     'file_name' => 'required', 
    ]); 

    if($request->hasFile('file_name')) { 
     $fname = $request->file('file_name')->getClientOriginalName(); 
     $request->file('file_name')->move(
      base_path() . '/public/files/documentation/', $fname 
     ); 
    } 

    $document = new Documentation(); 
    $document->name = $request->name; 
    $document->filename = $fname; 


    if($document->save()) { 
     $doc_ids = $request->documentation_appliance; 
     $document->appliances()->sync($doc_ids); 
    } 

    return view('backend.documentation.index', [ 
     'documentations' => $this->documents->getDocuments(), 
    ]); 
} 

數據表文檔corectly保存,圖像存儲,但我有保存數據到數據透視表的問題。屏幕顯示我這個錯誤:

FatalErrorException in compiled.php line 10191: 

Class 'appliances' not found 

in compiled.php line 10191 

沒有更多,我想我有不好的用處的地方或我做壞事別的?感謝大家的幫助。

回答