本文整理匯總了PHP中Craft::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP Craft::save方法的具體用法?PHP Craft::save怎麽用?PHP Craft::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Craft
的用法示例。
在下文中一共展示了Craft::save方法的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();
}
}