2016-09-20 141 views
-1

我想通過用戶角色 插入數據使用用戶角色來插入數據這裏是我的控制器如何在laravel 5.2

public function getWorks($class_id,Request $request) 
    { 
      @if(Auth::user()->role=="Teacher") 
      else if($validator->fails()) 
      { 
       $works = new assainments(); 
       $works -> title = $text; 
       //$works -> file = $fileName; 
       $works -> class_id = $class_id; 
       $works -> users_id = Auth::user()->id; 
       $works -> save(); 

      } 
      @endif 
     } 

我不能在這裏@if(Auth::user()->role=="Teacher")使用。我如何使用這個?

回答

0

你到目前爲止我做錯了什麼。這裏是概率答案:

public function getWorks($class_id,Request $request) 
{ 
     if(Auth::user()->role=="Teacher") 
     { 
     // do validation 
     // .... 
     // .... 

     if(!$validator->fails()) 
     { 
      $works = new assainments(); 
      $works -> title = $text; 
      //$works -> file = $fileName; 
      $works -> class_id = $class_id; 
      $works -> users_id = Auth::user()->id; 
      $works -> save(); 

     } 
     } 
     else 
     { 
     // do return false 
     return redirect()->back(); 
     } 
} 
+0

Thnx bro ... Helpfull ... – Shuvo