本文整理汇总了PHP中Validator::make方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::make方法的具体用法?PHP Validator::make怎么用?PHP Validator::make使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validator
的用法示例。
在下文中一共展示了Validator::make方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: putChangePassword
/**
* 动作:修改当前账号密码
* @return Response
*/
public function putChangePassword()
{
$response = array();
// 获取所有表单数据
$data = Input::all();
$admin = Session::get("admin");
// 验证旧密码
if (!Hash::check($data['password_old'], $admin->pwd)) {
$response['success'] = false;
$response['message'] = '原始密码错误';
return Response::json($response);
}
// 创建验证规则
$rules = array('password' => 'alpha_dash|between:6,16|confirmed');
// 自定义验证消息
$messages = array('password.alpha_dash' => '密码格式不正确。', 'password.between' => '密码长度请保持在:min到:max位之间。', 'password.confirmed' => '两次输入的密码不一致。');
// 开始验证
$validator = Validator::make($data, $rules, $messages);
if ($validator->passes()) {
// 验证成功
// 更新用户
$admin->pwd = Hash::make(Input::get('password'));
if ($admin->save()) {
$response['success'] = true;
$response['message'] = '密码修改成功';
} else {
$response['success'] = false;
$response['message'] = '密码修改失败';
}
} else {
$response['success'] = false;
$response['message'] = $validator->errors->first();
}
return Response::json($response);
}
示例2: crearProyecto
public function crearProyecto()
{
$data = Input::all();
$ciclo = $data['cicle'];
$ciclo == 1 ? $ciclo = 'Agosto-Enero' : ($ciclo = 'Enero-Julio');
//Valida los datos ingresados.
$notificaciones = ['year.required' => '¡Escriba un año!', 'year.numeric' => '¡El año debe ser numérico!'];
$validation = Validator::make($data, ['year' => 'required|numeric'], $notificaciones);
if ($validation->passes()) {
//Se revisa si había registros antes
$temp = Proyecto::select('ciclo', 'anio')->where('ciclo', $ciclo)->where('anio', $data['year'])->get();
//Si aún no había registros, se añaden las horas disponbiles por aula y día.
if (sizeof($temp) < 1) {
$idProyecto = Proyecto::insertGetId(['ciclo' => $ciclo, 'anio' => $data['year']]);
$aulas = Aula::count();
$horas = Hora::select('*')->where('id', '>', '0')->get();
for ($i = 2; $i <= $aulas; $i++) {
for ($k = 0; $k < 5; $k++) {
foreach ($horas as $hora) {
$temp = new Disponible();
$temp->id_aula = $i;
$temp->hora = $hora['id'];
$temp->dia = $k;
$temp->id_proyecto = $idProyecto;
$temp->save();
}
}
}
}
return Redirect::to('/proyectos/');
} else {
Input::flash();
return Redirect::to('/proyectos/editar-proyecto')->withInput()->withErrors($validation);
}
}
示例3: faqSend
public function faqSend()
{
$question = new Question();
$input = Input::all();
$captcha_string = Input::get('g-recaptcha-response');
$captcha_response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=6LcCwgATAAAAAKaXhPJOGPTBwX-n2-PPLZ7iupKj&response=' . $captcha_string);
$captcha_json = json_decode($captcha_response);
if ($captcha_json->success) {
$rules = ["sujetQuestion" => "required", "mail" => "required|email", "contenuQuestion" => "required"];
$messages = ["required" => ":attribute est requis pour l'envoi d'une question", "email" => "L'adresse email précisée n'est pas valide"];
$validator = Validator::make(Input::all(), $rules, $messages);
if ($validator->fails()) {
$messages = $validator->messages();
Session::flash('flash_msg', "Certains champs spécifiés sont incorrects.");
Session::flash('flash_type', "fail");
return Redirect::to(URL::previous())->withErrors($validator);
} else {
$question->fill($input)->save();
Session::flash('flash_msg', "Votre question nous est bien parvenue. Nous vous répondrons sous peu.");
Session::flash('flash_type', "success");
return Redirect::to(URL::previous());
}
} else {
Session::flash('flash_msg', "Champ de vérification incorrect ou non coché.");
Session::flash('flash_type', "fail");
return Redirect::to(URL::previous());
}
}
示例4: save
public function save () {
$param = Input::all();
$validator = Validator::make($param, [
'site_title' => 'required',
'meta_description' => 'required',
'meta_keywords' => 'required',
'email_support' => 'required|email',
'count_pagination' => 'required'
]);
if ( $validator->fails() ) {
$output = '';
$errors = $validator->messages()->toArray();
foreach ($errors as $error) {
$output .= $error[0] . '<br>';
}
return View::make('admin.elements.error')->with('errors', $output);
}
AppSettings::set('site_title', $param['site_title']);
AppSettings::set('meta_description', $param['meta_description']);
AppSettings::set('meta_keywords', $param['meta_keywords']);
AppSettings::set('email_support', $param['email_support']);
AppSettings::set('count_pagination', $param['count_pagination']);
return Redirect::to(URL::previous());
}
示例5: store
/**
* Upload the file and store
* the file path in the DB.
*/
public function store()
{
// Rules
$rules = array('name' => 'required', 'file' => 'required|max:20000');
$messages = array('max' => 'Please make sure the file size is not larger then 20MB');
// Create validation
$validator = Validator::make(Input::all(), $rules, $messages);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
$directory = "uploads/files/";
// Before anything let's make sure a file was uploaded
if (Input::hasFile('file') && Request::file('file')->isValid()) {
$current_file = Input::file('file');
$filename = Auth::id() . '_' . $current_file->getClientOriginalName();
$current_file->move($directory, $filename);
$file = new Upload();
$file->user_id = Auth::id();
$file->project_id = Input::get('project_id');
$file->name = Input::get('name');
$file->path = $directory . $filename;
$file->save();
return Redirect::back();
}
$upload = new Upload();
$upload->user_id = Auth::id();
$upload->project_id = Input::get('project_id');
$upload->name = Input::get('name');
$upload->path = $directory . $filename;
$upload->save();
return Redirect::back();
}
示例6: store
function store()
{
$rules = array('icao' => 'alpha_num|required', 'iata' => 'alpha_num', 'name' => 'required', 'city' => 'required', 'lat' => 'required|numeric', 'lon' => 'required|numeric', 'elevation' => 'required|numeric', 'country_id' => 'required|exists:countries,id', 'website' => 'url');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
Messages::error($validator->messages()->all());
return Redirect::back()->withInput();
}
if (is_null($airport = Airport::whereIcao(Input::get('icao'))->whereNew(true)->first())) {
$airport = new Airport();
$airport->icao = Input::get('icao');
$airport->name = Input::get('name');
$airport->new = true;
$airport->save();
}
Diff::compare($airport, Input::all(), function ($key, $value, $model) {
$change = new AirportChange();
$change->airport_id = $model->id;
$change->user_id = Auth::id();
$change->key = $key;
$change->value = $value;
$change->save();
}, ['name', 'iata', 'city', 'country_id', 'lat', 'lon', 'elevation', 'website']);
Messages::success('Thank you for your submission. We will check whether all information is correct and soon this airport might be available.');
return Redirect::back();
}
示例7: dologin
public function dologin()
{
$rules = array('username' => 'required', 'password' => 'required');
$message = array('required' => 'Data :attribute harus diisi', 'min' => 'Data :attribute minimal diisi :min karakter');
$validator = Validator::make(Input::all(), $rules, $message);
if ($validator->fails()) {
return Redirect::to('/')->withErrors($validator)->withInput(Input::except('password'));
} else {
$data = array('username' => Input::get('username'), 'password' => Input::get('password'));
if (Auth::attempt($data)) {
$data = DB::table('user')->select('user_id', 'level_user', 'username')->where('username', '=', Input::get('username'))->first();
//print_r($data);
//echo $data->id_users;
Session::put('user_id', $data->user_id);
Session::put('level', $data->level_user);
Session::put('username', $data->username);
//print_r(Session::all());
return Redirect::to("/admin/beranda");
} else {
Session::flash('messages', '
<div class="alert alert-danger alert-dismissable" >
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<strong>Peringatan...</strong><br>
Username dan password belum terdaftar pada sistem !
</div>
');
return Redirect::to('/')->withInput(Input::except('password'));
}
}
}
示例8: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
if (Auth::check()) {
// validate
// read more on validation at http://laravel.com/docs/validation
$rules = array('username' => 'required', 'email' => 'required');
$validator = Validator::make(Input::all(), $rules);
// process the login
if ($validator->fails()) {
return Redirect::to('users/' . $id . '/edit')->withErrors($validator)->withInput(Input::except('password'));
} else {
// store
$user = User::find($id);
$user->username = Input::get('username');
$user->email = Input::get('email');
$user->save();
// redirect
Session::flash('message', 'Successfully updated user');
return Redirect::to('users');
}
} else {
// User is not logged in
Session::flash('message', 'Please log in');
return Redirect::to('/');
}
}
示例9: postSave
public function postSave($id = null)
{
$validator = Validator::make(Input::all(), Appointment::$rules);
if ($validator->passes()) {
$event = Appointment::find(Input::get('id'));
if (!$event) {
$event = new Appointment();
}
$calendar = Calendar::find(explode('/', Input::get('date'))[0]);
if ($calendar) {
$day = explode('/', Input::get('date'))[1];
if ($day > 0 && $day <= $calendar->number_of_days) {
$event->name = Input::get('name');
$event->date = explode('/', Input::get('date'))[1];
$event->start_time = Input::get('start_time');
$event->end_time = Input::get('end_time');
$event->notes = Input::get('notes');
$event->calendar_id = $calendar->id;
$event->group_id = Input::get('group_id');
$event->user_id = Auth::user()->id;
$event->save();
return Response::json(array('status' => 'success', $event));
} else {
$validator->messages()->add('date', 'The day is invalid.');
}
} else {
$validator->messages()->add('date', 'The month is invalid.');
}
}
return Response::json(array('status' => 'error', 'errors' => $validator->messages()));
}
示例10: avatarUpload
/**
* 头像上传
*
* 这里不直接注入自定义的 Request 类, 因为直接注入的话如果上传的文件不符合规则, 直接被拦截了, 进不到这个方法, 实现不了 AJAX 提交
* 因此在这方法里面进行验证, 再把错误用 json 返回到页面上
*
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function avatarUpload(Request $request)
{
$file = $request->file('avatar');
$avatarRequest = new AvatarRequest();
$validator = \Validator::make($request->only('avatar'), $avatarRequest->rules());
if ($validator->fails()) {
return \Response::json(['success' => false, 'errors' => $validator->messages()]);
}
$user = $this->authRepository->user();
$destination = 'avatar/' . $user->username . '/';
// 文件最终存放目录
file_exists($destination) ? '' : mkdir($destination, 0777);
$clientName = $file->getClientOriginalName();
// 原文件名
$extension = $file->getClientOriginalExtension();
// 文件扩展名
$newName = md5(date('ymd') . $clientName) . '.' . $extension;
$avatarPath = '/' . $destination . $newName;
$oldAvatar = substr($user->avatar, 1);
// 旧头像路径, 把路径最前面的 / 删掉
if ($file->move($destination, $newName)) {
$this->authRepository->update(['avatar' => $avatarPath], $user->id);
file_exists($oldAvatar) ? unlink($oldAvatar) : '';
return \Response::json(['success' => true, 'avatar' => $avatarPath]);
}
}
示例11: postUpdate
public function postUpdate($id)
{
$archivo = Input::file('archivo');
$imagen = Input::file('imagen');
$validator = Validator::make(array('archivo' => $archivo, 'imagen' => $imagen), array('archivo' => 'mimes:png,jpeg,gif,txt,ppt,pdf,doc,xls', 'imagen' => 'mimes:png,jpeg,gif'), array('mimes' => 'Tipo de archivo inválido, solo se admite los formatos PNG, JPEG, y GIF'));
if ($validator->fails()) {
return Redirect::to($this->route . '/create')->with('msg_err', Lang::get('messages.companies_create_img_err'));
} else {
$arquivo = SFArquivos::find($id);
$arquivo->titulo_archivo = Input::get('titulo_archivo');
$arquivo->id_categoria = Input::get('id_categoria');
$arquivo->resumem = Input::get('resumem');
$arquivo->tipo_archivo = Input::get('tipo_archivo');
if ($archivo != "") {
$url = $archivo->getRealPath();
$extension = $archivo->getClientOriginalExtension();
$name = str_replace(' ', '', strtolower(Input::get('titulo_archivo'))) . date('YmdHis') . rand(2, 500 * 287) . '.' . $extension;
$size = $archivo->getSize();
$mime = $archivo->getMimeType();
$archivo->move(public_path('uploads/arquivos/'), $name);
$arquivo->archivo = $name;
}
if ($imagen != "") {
$imagen = $this->uploadHeader($imagen);
$arquivo->imagen = $imagen;
}
$arquivo->save();
return Redirect::to($this->route)->with('msg_success', Lang::get('messages.companies_create', array('title' => $arquivo->title)));
}
}
示例12: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$validasi = Validator::make(Input::all(), Berita::$rules, Berita::$pesan);
if ($validasi->fails()) {
return Redirect::back()->withInput()->withErrors($validasi);
} else {
$berita = Berita::find($id);
$berita->judul = Input::get('judul');
$berita->isi = Input::get('isi');
$berita->id_kategori = Input::get('kategori');
if (Input::hasFile('gambar')) {
$file = Input::file('gambar');
$filename = str_random(5) . '-' . $file->getClientOriginalName();
$destinationPath = 'uploads/berita/';
$file->move($destinationPath, $filename);
if ($berita->gambar) {
$fotolama = $berita->gambar;
$filepath = public_path() . DIRECTORY_SEPARATOR . 'uploads/berita' . DIRECTORY_SEPARATOR . $berita->gambar;
try {
File::delete($filepath);
} catch (FileNotFoundException $e) {
}
}
$berita->gambar = $filename;
}
$berita->save();
Session::flash('pesan', "<div class='alert alert-info'>Berita Berhasil diupdate</div>");
return Redirect::to('admin/berita');
}
}
示例13: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
//Validate
$rules = array('name' => 'required');
$validator = Validator::make(Input::all(), $rules);
// process the validation
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput(Input::except('password'));
} else {
// Update
$commodity = Commodity::find($id);
$commodity->name = Input::get('name');
$commodity->description = Input::get('description');
$commodity->metric_id = Input::get('unit_of_issue');
$commodity->unit_price = Input::get('unit_price');
$commodity->item_code = Input::get('item_code');
$commodity->storage_req = Input::get('storage_req');
$commodity->min_level = Input::get('min_level');
$commodity->max_level = Input::get('max_level');
try {
$commodity->save();
return Redirect::route('commodity.index')->with('message', trans('messages.success-updating-commodity'))->with('activecommodity', $commodity->id);
} catch (QueryException $e) {
Log::error($e);
}
}
}
示例14: create
public function create()
{
$message = null;
if ($val = \Input::get('val')) {
/**
* @var $privacy
*/
extract($val);
if ($privacy == 1) {
$validator = \Validator::make($val, ['public_name' => 'required|predefined|validalpha|min:3', 'public_url' => 'required|predefined|validalpha|min:3|alpha_dash|slug|unique:communities,slug']);
} else {
$validator = \Validator::make($val, ['private_name' => 'required|predefined|validalpha|min:3', 'private_url' => 'required|predefined|validalpha|min:3|alpha_dash|slug|unique:communities,slug']);
}
if (!$validator->fails()) {
$community = $this->communityRepostory->create($val);
if ($community) {
//redirect to community page
return \Redirect::to($community->present()->url());
} else {
$message = trans('community.create-error');
}
} else {
$message = $validator->messages()->first();
}
}
return $this->preRender($this->theme->section('community.create', ['message' => $message]), $this->setTitle(trans('community.create')));
}
示例15: valid
/**
* Validate the Model
* runs the validator and binds any errors to the model
*
* @param array $rules
* @param array $messages
* @return bool
*/
public function valid($rules = array(), $messages = array())
{
// innocent until proven guilty
$valid = true;
if (!empty($rules) || !empty(static::$rules)) {
// check for overrides
$rules = empty($rules) ? static::$rules : $rules;
$messages = empty($messages) ? static::$messages : $messages;
// if the model exists, this is an update
if ($this->exists) {
// and only include dirty fields
$data = $this->get_dirty();
// so just validate the fields that are being updated
$rules = array_intersect_key($rules, $data);
} else {
// otherwise validate everything!
$data = $this->attributes;
}
// construct the validator
$validator = Validator::make($data, $rules, $messages);
$valid = $validator->valid();
// if the model is valid, unset old errors
if ($valid) {
$this->errors->messages = array();
} else {
$this->errors = $validator->errors;
}
}
return $valid;
}