Beispiel #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     if (Auth::check() && $this->rolechucnangs && $this->rolechucnangs->Them == 1) {
         $role = new Role();
         $role->name = $request->input('name');
         $role->slug = $request->input('name');
         $role->description = $request->input('description');
         $role->save();
         $id = $role->id;
         //echo $id;
         $xem = $request->input('xem');
         $them = $request->input('them');
         $xoa = $request->input('xoa');
         $sua = $request->input('sua');
         $chucnang = $request->input('chucnang');
         if ($chucnang != NULL) {
             $role->danhmuchucnangs()->sync($chucnang);
         }
         // cap nhat lại role moi
         if (count($xem) > 0) {
             foreach ($xem as $key => $value) {
                 \DB::table('role_chucnangs')->where('danhmucchucnang_id', $value)->where('role_id', $id)->update(['Xem' => 1]);
             }
         }
         if (count($them) > 0) {
             foreach ($them as $key => $value) {
                 \DB::table('role_chucnangs')->where('danhmucchucnang_id', $value)->where('role_id', $id)->update(['Them' => 1]);
             }
         }
         if (count($xoa) > 0) {
             foreach ($xoa as $key => $value) {
                 \DB::table('role_chucnangs')->where('danhmucchucnang_id', $value)->where('role_id', $id)->insert(['Xoa' => 1]);
             }
         }
         if (count($sua) > 0) {
             foreach ($sua as $key => $value) {
                 \DB::table('role_chucnangs')->where('danhmucchucnang_id', $value)->where('role_id', $id)->update(['Sua' => 1]);
             }
         }
         if (count($chucnang) > 0) {
             foreach ($chucnang as $key => $value) {
                 \DB::table('role_chucnangs')->where('danhmucchucnang_id', $value)->where('role_id', $id)->update(['Danhsach' => 1]);
             }
         }
         return \Redirect::route('role.index')->with('message', 'Nhập thành công!');
     } else {
         return \Redirect::route('role.index')->with('message-error', 'Không có quyền truy cập');
     }
 }