本文整理汇总了PHP中Craft::addTagOrCreateNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Craft::addTagOrCreateNew方法的具体用法?PHP Craft::addTagOrCreateNew怎么用?PHP Craft::addTagOrCreateNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Craft
的用法示例。
在下文中一共展示了Craft::addTagOrCreateNew方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateCraft
public function updateCraft(Craft $craft)
{
$inputs = ['title' => Input::get('title'), 'description' => Input::get('description'), 'title_ru' => Input::get('title_ru'), 'description_ru' => Input::get('description_ru'), 'link' => Input::get('link'), 'image' => Input::file('image'), 'user_id' => Input::get('uid'), 'name' => Input::get('tag')];
$attributeNames = ['name' => 'Tag name'];
$valid = Validator::make($inputs, Craft::$rules);
$valid->setAttributeNames($attributeNames);
$valid->sometimes('name', 'unique:tags|min:3|max:12', function ($inputs) {
return !is_numeric($inputs['name']);
});
if ($valid->passes()) {
$craft->title = $inputs['title'];
$craft->description = $inputs['description'];
$craft->title_ru = $inputs['title_ru'];
$craft->description_ru = $inputs['description_ru'];
$craft->link = $inputs['link'];
$craft->user_id = $inputs['user_id'];
$tag = $inputs['name'];
$image = $inputs['image'];
if (isset($image)) {
list($width, $height) = getimagesize($image);
$ratio = $height / $width;
$filename = date('Y-m-d-H:i:s') . "-" . $image->getClientOriginalName();
$width = $width > 600 ? 600 : $width;
$height = $height > 600 ? $width * $ratio : $height;
Image::make($image->getRealPath())->resize($width, $height)->save(public_path() . '/img/pncpictures/' . $filename);
$craft->image = 'img/pncpictures/' . $filename;
} else {
$craft->image = '';
}
if ($tag != 'default') {
$craft->addTagOrCreateNew($tag, $inputs['user_id']);
}
$craft->save();
return Redirect::back()->with('success', Lang::choice('messages.Crafts', 1) . ' ' . trans('is updated'));
} else {
return Redirect::back()->withErrors($valid)->withInput();
}
}