本文整理匯總了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}");
}