本文整理汇总了PHP中app\Board::assets方法的典型用法代码示例。如果您正苦于以下问题:PHP Board::assets方法的具体用法?PHP Board::assets怎么用?PHP Board::assets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Board
的用法示例。
在下文中一共展示了Board::assets方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteAssets
/**
* Clear singular board assets.
*
* @return Response
*/
public function deleteAssets(Request $request, Board $board)
{
$input = Input::all();
$validator = Validator::make($input, ['asset_type' => ["required", "in:board_banner,board_icon,file_deleted,file_spoiler"]]);
if (!$validator->passes()) {
return redirect()->back()->withErrors($validator->errors());
}
$assets = $board->assets()->with('storage')->where('asset_type', $input['asset_type'])->get();
foreach ($assets as $asset) {
$asset->delete();
$asset->storage->challengeExistence();
}
Event::fire(new BoardWasModified($board));
return $this->getAssets($board);
}
示例2: patchAssets
/**
* Removes existing assets.
*
* @return Response
*/
public function patchAssets(Board $board)
{
if (!$board->canEditConfig($this->user)) {
return abort(403);
}
$assetsToKeep = Input::get('asset', []);
$assetsToName = Input::get('asset_name', []);
$assetsToReplace = Input::file('asset_file', []);
$assetType = Input::get('patching', false);
$assets = $board->assets()->where('asset_type', $assetType)->get();
foreach ($assets as $assetIndex => $asset) {
if (!isset($assetsToKeep[$asset->board_asset_id]) || !$assetsToKeep[$asset->board_asset_id]) {
$asset->delete();
$asset->storage->challengeExistence();
} else {
$changed = false;
if (isset($assetsToName[$asset->board_asset_id])) {
$changed = true;
$asset->asset_name = $assetsToName[$asset->board_asset_id];
}
if (isset($assetsToReplace[$asset->board_asset_id]) && !is_null($assetsToReplace[$asset->board_asset_id])) {
$newFile = $assetsToReplace[$asset->board_asset_id];
switch ($assetType) {
// Don't copy this logic.
// This is a lazy duplicate of putAssets.
case "board_flags":
$imageRules = array_merge(["required"], BoardAsset::getRulesForFlags($board));
$validator = Validator::make(['file' => $newFile], ['file' => $imageRules]);
if (!$validator->passes()) {
return redirect()->back()->withErrors($validator->errors());
}
$storage = FileStorage::storeUpload($newFile);
if ($storage->exists) {
$changed = true;
$asset->file_id = $storage->file_id;
} else {
return redirect()->back()->withErrors(["validation.custom.file_generic"]);
}
break;
}
}
$asset->save();
}
}
Event::fire(new BoardWasModified($board));
return $this->getAssets($board);
}