当前位置: 首页>>代码示例>>PHP>>正文


PHP Board::setOwner方法代码示例

本文整理汇总了PHP中app\Board::setOwner方法的典型用法代码示例。如果您正苦于以下问题:PHP Board::setOwner方法的具体用法?PHP Board::setOwner怎么用?PHP Board::setOwner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Board的用法示例。


在下文中一共展示了Board::setOwner方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: putCreate

 /**
  * Allows for the creation of a new board.
  *
  * @return Response
  */
 public function putCreate(Request $request)
 {
     if (!$this->user->canCreateBoard()) {
         return abort(403);
     }
     $configErrors = [];
     // Check time and quantity restraints.
     if (!$this->user->canAdminConfig()) {
         $boardLastCreated = null;
         $boardsOwned = 0;
         $boardCreateTimer = $this->option('boardCreateTimer');
         $boardsCreateMax = $this->option('boardCreateMax');
         if (!$this->user->isAnonymous()) {
             foreach ($this->user->createdBoards as $board) {
                 ++$boardsOwned;
                 if (is_null($boardLastCreated) || $board->created_at->timestamp > $boardLastCreated->timestamp) {
                     $boardLastCreated = $board->created_at;
                 }
             }
         }
         if ($boardsCreateMax > 0 && $boardsOwned >= $boardsCreateMax) {
             $configErrors[] = Lang::choice("panel.error.board.create_more_than_max", $boardsCreateMax, ['boardsCreateMax' => $boardsCreateMax]);
         }
         if ($boardCreateTimer > 0 && (!is_null($boardLastCreated) && $boardLastCreated->diffInMinutes() < $boardCreateTimer)) {
             $configErrors[] = Lang::choice("panel.error.board.create_so_soon", $boardLastCreated->addMinutes($boardCreateTimer)->diffInMinutes() + 1, ['boardCreateTimer' => $boardLastCreated->diffInMinutes()]);
         }
     }
     if (count($configErrors)) {
         return redirect()->back()->withInput()->withErrors($configErrors);
     }
     // Validate input.
     // If the user is anonymous, we must also be creating an account.
     $input = Input::all();
     if ($this->user->isAnonymous()) {
         $validator = $this->registrar->validator($input);
         if ($validator->fails()) {
             $this->throwValidationException($request, $validator);
         }
     }
     // Generate a list of banned URIs.
     $bannedUris = array_filter(explode("\n", $this->option('boardUriBanned')));
     $bannedUris[] = "cp";
     $bannedUris = implode(",", $bannedUris);
     // Validate the basic boardconstraints.
     $input['board_uri'] = strtolower((string) $input['board_uri']);
     $requirements = ['board_uri' => ["required", "unique:boards,board_uri", "not_in:{$bannedUris}", "string", "regex:(" . Board::URI_PATTERN . ")"], 'title' => "required|string|between:1,255", 'description' => "string|between:0,255"];
     $validator = Validator::make($input, $requirements);
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     if ($this->user->isAnonymous()) {
         $this->auth->login($this->registrar->create($request->all()));
         $this->user = $this->auth->user();
     }
     // Create the board.
     $board = new Board(['board_uri' => $input['board_uri'], 'title' => $input['title'], 'description' => $input['description'], 'created_by' => $this->user->user_id, 'operated_by' => $this->user->user_id]);
     $board->save();
     // Seed board ownership permissions.
     $board->setOwner($this->user);
     $this->log("log.board.create", $board->board_uri);
     Event::fire(new BoardWasCreated($board, $this->user));
     return redirect("cp/board/{$board->board_uri}");
 }
开发者ID:swagnarok,项目名称:infinity-next,代码行数:68,代码来源:BoardsController.php


注:本文中的app\Board::setOwner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。