本文整理汇总了PHP中app\Board::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Board::save方法的具体用法?PHP Board::save怎么用?PHP Board::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Board
的用法示例。
在下文中一共展示了Board::save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: patchIndex
/**
* Validate and save changes.
*
* @return Response
*/
public function patchIndex(BoardConfigRequest $request, Board $board)
{
$input = $request->all();
$optionGroups = $request->getBoardOptions();
foreach ($optionGroups as $optionGroup) {
foreach ($optionGroup->options as $option) {
$setting = BoardSetting::firstOrNew(['option_name' => $option->option_name, 'board_uri' => $board->board_uri]);
$option->option_value = $input[$option->option_name];
$setting->option_value = $input[$option->option_name];
$setting->save();
}
}
$board->title = $input['boardBasicTitle'];
$board->description = $input['boardBasicDesc'];
$board->is_overboard = isset($input['boardBasicOverboard']) && !!$input['boardBasicOverboard'];
$board->is_indexed = isset($input['boardBasicIndexed']) && !!$input['boardBasicIndexed'];
$board->is_worksafe = isset($input['boardBasicWorksafe']) && !!$input['boardBasicWorksafe'];
$board->save();
Event::fire(new BoardWasModified($board));
return $this->view(static::VIEW_CONFIG, ['board' => $board, 'groups' => $optionGroups]);
}
示例2: importInfinityRolesAndBoards
/**
* Imports users and creates roles based on addition data in that row.
*
* @return void
*/
public function importInfinityRolesAndBoards()
{
# BORROW SEEDERS
require base_path() . "/database/seeds/OptionSeeder.php";
require base_path() . "/database/seeds/PermissionSeeder.php";
require base_path() . "/database/seeds/RoleSeeder.php";
# DESTROY SEQUENCE
if (DB::connection() instanceof \Illuminate\Database\PostgresConnection) {
$this->comment("\tDropping role sequence.");
DB::statement("DROP SEQUENCE IF EXISTS roles_role_id_seq CASCADE;");
}
$PermissionSeeder = new \PermissionSeeder();
$PermissionSeeder->setCommand($this);
$PermissionSeeder->run();
$PermissionGroupSeeder = new \PermissionGroupSeeder();
$PermissionGroupSeeder->setCommand($this);
$PermissionGroupSeeder->run();
$OptionSeeder = new \OptionSeeder();
$OptionSeeder->setCommand($this);
$OptionSeeder->run();
$OptionGroupSeeder = new \OptionGroupSeeder();
$OptionGroupSeeder->setCommand($this);
$OptionGroupSeeder->run();
$RoleSeeder = new \RoleSeeder();
$RoleSeeder->setCommand($this);
$RoleSeeder->runMaster();
$RolePermissionSeeder = new \RolePermissionSeeder();
$RolePermissionSeeder->setCommand($this);
$RolePermissionSeeder->run();
\Artisan::call('cache:clear');
# REPAIR SEQUENCE
if (DB::connection() instanceof \Illuminate\Database\PostgresConnection) {
$this->comment("\tCreating role_id sequence again.");
DB::statement("CREATE SEQUENCE roles_role_id_seq;");
$pgSeqNext = DB::table('roles')->select(DB::raw("(MAX(\"role_id\") + 1) AS next"))->pluck("next");
DB::statement("ALTER SEQUENCE roles_role_id_seq OWNED BY \"roles\".\"role_id\" RESTART WITH {$pgSeqNext};");
DB::statement("ALTER TABLE roles ALTER COLUMN role_id SET DEFAULT nextval('roles_role_id_seq');");
}
# THEIR TABLES
$tBoardsTable = $this->tcon->table("boards")->join('board_create', 'boards.uri', '=', 'board_create.uri')->select('boards.*', 'board_create.time');
$tModsTable = $this->tcon->table("mods");
# BEGIN USER IMPORT
$this->info("\tImporting Users ...");
$userAdmin = null;
$userBoardRelationships = [];
$usersImported = 0;
$tModsTable->chunk(100, function ($mods) use(&$userAdmin, &$userBoardRelationships, &$usersImported) {
$this->line("\t\tHandling 100 users ...");
foreach ($mods as $mod) {
# CREATE USER
$user = new User(['username' => $mod->username, 'email' => property_exists($mod, "email") ? $mod->email ?: null : null, 'password' => null, 'password_legacy' => json_encode(['hasher' => "Vichan", 'hash' => $mod->password, 'salt' => $mod->salt])]);
// 8chan has an issue with duplicates.
try {
$saved = $user->save();
} catch (\Exception $e) {
$saved = false;
}
if ($saved) {
++$usersImported;
# REMEMBER ROLES
if ($mod->boards) {
// TODO
// Pull these values from config when formal importer created.
switch ($mod->type) {
// Janitor (Disabled)
case 10:
// Disabled
// Disabled
case 99:
$this->comment("\t\tMod {$user->username} is disabled.");
break;
// Board volunteer
// Board volunteer
case 19:
// Board owner
// Board owner
case 20:
if (!isset($userBoardRelationships[$mod->boards])) {
$userBoardRelationships[$mod->boards] = [];
}
$userBoardRelationships[$mod->boards][$user->user_id] = $mod->type;
break;
// Global volunteer
// Global volunteer
case 25:
$this->comment("\t\tSetting {$user->username} to Global Mod.");
$user->roles()->attach(Role::ID_MODERATOR);
break;
// Admin
// Admin
case 30:
$this->comment("\t\tSetting {$user->username} to Global Admin.");
$user->roles()->attach(Role::ID_ADMIN);
$userAdmin = $userAdmin ?: $user;
break;
//.........这里部分代码省略.........
示例3: 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}");
}