本文整理汇总了PHP中app\Category::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::validate方法的具体用法?PHP Category::validate怎么用?PHP Category::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Category
的用法示例。
在下文中一共展示了Category::validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$parent = !empty($request->input('parent_id')) ? Category::find($request->input('parent_id')) : null;
$data = $request->only(['name', 'name_ru', 'parent_id']);
$category = new Category($data);
if (($messages = $category->validate()) === true) {
Category::create($data, $parent);
$response = array('result' => "{$request->input('name')} successfully added!");
return \Response::json($response, 200);
} else {
return \Response::json($messages);
}
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
//
$category = new Category();
$category->name = $request->input('name');
$category->alias = $request->input('alias');
$category->ordering = $request->input('ordering');
if ($category->validate()) {
$category->save();
Session::flash('success', 'add success');
} else {
$errors = $category->errors;
$messages = '';
//dd($errors);
foreach ($errors->all() as $error) {
$messages .= $error . '<br>';
}
Session::flash('error', $messages);
}
return redirect('category/create')->withInput();
}
示例3: create
public function create()
{
$data = ['name' => Input::get('name'), 'description' => Input::get('description'), 'parent_id' => Input::get('parent_id'), 'id_path' => Input::get('id_path'), 'position' => Input::get('position')];
if (isset($data) && is_array($data)) {
$category = new Category();
if ($category->validate($data)) {
$category->name = $data['name'];
$category->description = $data['description'];
$category->parent_id = $data['parent_id'];
$category->id_path = $data['id_path'];
$category->position = $data['position'];
$create = $category->save();
if (!$create) {
return Redirect::route('categories')->with(['msg' => 'Failed to create!']);
}
return Redirect::route('categories')->with(['msg' => 'Successfully created!']);
}
return Redirect::route('categories')->with(['msg' => 'Failed to create!']);
}
return Redirect::route('categories')->with(['msg' => 'Failed to create!']);
}