如何在laravel创造独特的蛞蝓和验证它们?
这里是我的验证代码:
$this->validate($request,[
'company_name' => 'required|unique:admin_users,company_name,slug|max:191',
]);
这里是我的蛞蝓代码:
$db_filed->company_name = str_slug($request->company_name, '-');
谢谢。
如何在laravel创造独特的蛞蝓和验证它们?
这里是我的验证代码:
$this->validate($request,[
'company_name' => 'required|unique:admin_users,company_name,slug|max:191',
]);
这里是我的蛞蝓代码:
$db_filed->company_name = str_slug($request->company_name, '-');
谢谢。
设置一个FormRequest做的,像这样的规则路由的验证:
https://laravel.com/docs/5.4/validation#form-request-validation
public function rules()
{
return [
'company_name' => 'required|unique:admin_users,company_name,slug|max:191'
];
}
或者你需要在分配给该公司的名称之前创建蛞蝓。
https://laravel.com/docs/5.4/validation#manually-creating-validators
$slug = str_slug($request->company_name, '-');
$validator = Validator::make(['company_name' => $slug], [
'company_name' => 'required|unique:admin_users,company_name,slug|max:191'
]);
if (!$validator->fails()) {
$db_filed->company_name = $slug;
$db_filled->save();
}
我想这样的,现在它的工作,
下面是代码形式:
<div class="form-group">
<input type="text" class="form-control" placeholder="Company Name" name="company_name" value="{{ ucwords(str_replace('-',' ',old('company_name'))) }}" required>
</div>
下面是控制器代码:
public function store(Request $request)
{
$request['company_name'] = str_slug($request->company_name, '-');
$this->validate($request,[
'company_name' => "required|unique:admin_users,company_name|max:191",
]);
$db_filed = new AdminUser;
$db_filed->company_name = $request->company_name;
$db_filed->save();
}
你可以创建你的控制器内塞可能是存储功能像这里面的
public function store(CompanyNameRequest $request)
{
$slug = uniqid();
$ticket = new CompaanyName(array(
'title' => $request->get('title'),
'content' => $request->get('content'),
'slug' => $slug
));
$ticket->save();
return redirect('/contact')->with('status', 'Your order is been proccess! Its unique id is: '.$slug);
}