Esempio n. 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     // Validate the forum
     $this->validate($request, ['name' => 'required|unique:forums|max:255', 'description' => 'required']);
     // Create a new Forum
     $forum = new Forum();
     $forum->name = $request->name;
     $forum->slug = str_slug($request->name, '-');
     $forum->description = $request->description;
     if ($forum->save()) {
         // Grant the admin access to the forum
         $admin = Role::find(1);
         // Admin should be created when built, shouldn't be an issue
         $accessForum = new Permission();
         $accessForum->name = 'access-forum-' . $forum->id;
         $accessForum->display_name = 'Access ' . $forum->name;
         // optional
         $accessForum->description = 'Ability to access and post in ' . $forum->name;
         // optional
         $accessForum->save();
         $admin->attachPermission($accessForum);
         Session::flash('alert-success', 'Forum created.');
     } else {
         Session::flash('alert-error', 'Could not create forum.');
     }
     return redirect('dashboard');
 }