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