本文整理匯總了PHP中app\Page::increment方法的典型用法代碼示例。如果您正苦於以下問題:PHP Page::increment方法的具體用法?PHP Page::increment怎麽用?PHP Page::increment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Page
的用法示例。
在下文中一共展示了Page::increment方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$validator = Validator::make($request->all(), ['title' => 'required|min:5|max:60|unique:pages']);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput();
}
$page = new Page();
if ($request->sort_id > 0) {
$page->sort_id = $request->sort_id;
} else {
$page->sort_id = $page->increment('sort_id', 1);
}
$page->title = $request->title;
$page->slug = !empty($request->slug) ? $request->slug : str_slug($request->title);
$page->meta_title = $request->meta_title;
$page->meta_description = $request->meta_description;
$page->text = $request->text;
$page->lang = $request->lang;
if ($request->status == 'on') {
$page->status = 1;
} else {
$page->status = 0;
}
$page->save();
return redirect('/admin/pages')->with('status', 'Страница добавлена!');
}