我想按用户角色插入数据 这是我的控制器
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 :(得分: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();
}
}