当前位置: 首页>>代码示例>>PHP>>正文


PHP Validator::make方法代码示例

本文整理汇总了PHP中Illuminate\Support\Facades\Validator::make方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::make方法的具体用法?PHP Validator::make怎么用?PHP Validator::make使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Facades\Validator的用法示例。


在下文中一共展示了Validator::make方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: postCreate

 public function postCreate()
 {
     $rules = array('name' => 'required', 'cover_image' => 'required|image');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::route('create_album_form')->withErrors($validator)->withInput();
     }
     // end if
     $file = Input::file('cover_image');
     $random_name = str_random(8);
     $destinationPath = 'albums/';
     $extension = $file->getClientOriginalExtension();
     $filename = $random_name . "." . $extension;
     $uploadSuccess = Input::file('cover_image')->move($destinationPath, $filename);
     $album = Album::create(array('name' => Input::get('name'), 'description' => Input::get('description'), 'cover_image' => $filename, 'user_id' => \Sentry::getUser()->id));
     /*
           $filename = Input::file('cover_image');
           $random_name = str_random(8);
           $destinationPath = 'albums/';
           $extension = $filename->getClientOriginalExtension();
           $uploadSuccess = Input::file('cover_image')->move($destinationPath, $filename . "." . $extension);
           $album = Album::create(array(
             'name' => Input::get('name'),
             'description' => Input::get('description'),
             'cover_image' => $filename . "." . $extension,
           ));
     */
     return Redirect::route('show_album', array('id' => $album->id));
 }
开发者ID:deadlance,项目名称:laravel_project_test_2,代码行数:29,代码来源:AlbumsController.php

示例2: test_only_specific_locales_required

 public function test_only_specific_locales_required()
 {
     $validator = Validator::make(['name' => ['en' => 'One', 'sp' => 'Uno']], ['name.en' => 'required']);
     $this->assertTrue($validator->passes());
     $validator = Validator::make(['name' => ['sp' => 'Uno']], ['name.en' => 'required']);
     $this->assertFalse($validator->passes());
 }
开发者ID:themsaid,项目名称:laravel-multilingual,代码行数:7,代码来源:ValidationTest.php

示例3: edit

 /**
  * Edit page
  *
  * @param Request $request
  * @param int $id
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
  */
 public function edit(Request $request, $id = 0)
 {
     if ($request->isMethod('post')) {
         $rules = ['name' => 'required|unique:categories,name,' . $id, 'alias' => 'required|unique:categories,alias,' . $id, 'content' => 'required'];
         Validator::make($request->all(), $rules)->validate();
         $page = Category::find($id);
         $page->name = $request->input('name');
         $page->alias = $request->input('alias');
         $page->meta_keys = $request->input('meta_keys');
         $page->meta_desc = $request->input('meta_desc');
         if ($request->has('parent')) {
             $page->parent_id = $request->input('parent');
             $page->type = 2;
         } else {
             $page->type = 1;
         }
         $page->publish = $request->has('publish');
         $page->save();
         $page_content = $page->content;
         $page_content->content = $request->input('content');
         $page_content->save();
         return redirect()->route('pages');
     } else {
         $page = Category::getCategoryById($id);
         if (empty($page)) {
             return redirect()->back();
         } else {
             $pages = Category::getParentCategories($id);
             return view('admin.page.edit', compact('pages', 'page'));
         }
     }
 }
开发者ID:GHarutyunyan,项目名称:cms,代码行数:39,代码来源:PageController.php

示例4: postOrder

 public function postOrder()
 {
     log::debug('postOrder::Input params');
     log::debug(Input::all());
     //Validation rules
     $rules = array('pizza_marinara' => array('required', 'integer', 'between:0,3'), 'pizza_margherita' => array('required', 'integer', 'between:0,3'), 'olio' => array('min:1|max:20'), 'name' => array('required', 'min:1|max:20'), 'email' => array('required', 'email', 'min:1|max:20'), 'freeOrder' => array('exists:menu,dish'));
     // The validator
     $validation = Validator::make(Input::all(), $rules);
     // Check for fails
     if ($validation->fails()) {
         // Validation has failed.
         log::error('Validation has failed');
         $messages = $validation->messages();
         $returnedMsg = "";
         foreach ($messages->all() as $message) {
             $returnedMsg = $returnedMsg . " - " . $message;
         }
         log::error('Validation fail reason: ' . $returnedMsg);
         return redirect()->back()->withErrors($validation);
     }
     log::debug('Validation passed');
     $msg = array('email' => Input::get('email'), 'name' => Input::get('name'));
     $response = Event::fire(new ExampleEvent($msg));
     $response = Event::fire(new OrderCreated($msg));
     return view('orderdone', ['msg' => $msg]);
 }
开发者ID:WebYourMind,项目名称:courses-laravel5,代码行数:26,代码来源:NewOrderController.php

示例5: update

 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $service = service::findOrFail($id);
     $validator = Validator::make($data = Input::all(), service::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     /**
      * Check if Request param contains
      * status, if so activate
      * if not deactivate status
      */
     $status_exists = false;
     foreach ($data as $key => $value) {
         if ($key == 'status') {
             $status_exists = true;
         }
     }
     if ($status_exists) {
         $data['status'] = 1;
     } else {
         $data['status'] = 0;
     }
     $service->update($data);
     return Redirect::route('admin.services.index');
 }
开发者ID:hshifaz,项目名称:website,代码行数:33,代码来源:servicesController.php

示例6: createUser

 /**
  * This function create a new user after validate the request with the class NewUserRequest
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function createUser(Request $request)
 {
     switch ($request->input('type')) {
         //only for facebook user
         case 'facebook':
             $rules = ['email' => 'email|required', 'firstname' => 'required', 'facebook_id' => 'required', 'token' => 'required'];
             $validator = Validator::make($request->all(), $rules);
             if ($validator->fails()) {
                 return response()->json($validator->errors(), 400);
             }
             return $this->loginFacebookUser($request);
             break;
             //For every new user
         //For every new user
         default:
             $rules = ['email' => 'email|required', 'firstname' => 'required', 'password' => 'required'];
             $validator = Validator::make($request->all(), $rules);
             if ($validator->fails()) {
                 return response()->json($validator->errors(), 400);
             }
             $user = new User();
             $user->fill($request);
             if (!$user->save()) {
                 return response()->json('Error, the user was not created', 400);
             }
             return response()->json('success', 200);
     }
 }
开发者ID:jarriaga,项目名称:endaroo,代码行数:33,代码来源:UserController.php

示例7: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store($jenis)
 {
     if ($jenis == 'kategori') {
         $rules = array("judul" => "required", "status" => "required");
         $data = new Kategori();
         $validator = Validator::make(Input::all(), $rules);
         if ($validator->passes()) {
             $data->judul = strtolower(Input::get('judul'));
             $data->aktif = Input::get('status');
             $data->save();
             return redirect('/bos/kategori');
         } else {
             return back()->withInput()->with('message', 'Lengkapi data terlebih dahulu');
         }
     }
     if ($jenis == 'artikel') {
         $rules = array("judul" => "required");
         $valid = Validator::make(Input::all(), $rules);
         if ($valid->passes()) {
             $data = new Artikel();
             $data->judul = ucwords(Input::get('judul'));
             $data->slug = strtolower(str_replace(" ", "-", trim(Input::get('judul'))));
             $data->kategori = Input::get('kategori');
             $data->aktif = Input::get('aktif');
             $data->isi = Input::get('isi');
             $data->save();
             return redirect('/bos/artikel');
         } else {
             return back()->withInput()->with('message', 'Lengkapi data anda terlebih dahulu');
         }
     }
 }
开发者ID:andreepratama27,项目名称:melayupedia,代码行数:37,代码来源:BlogController.php

示例8: sendContactForm

 public function sendContactForm()
 {
     $is_mail_sent = false;
     // Get data
     $lastname = post('lastname');
     $firstname = post('firstname');
     $email = post('email');
     $subject = post('subject');
     $message_body = post('message');
     $inputs = ['lastname' => $lastname, 'firstname' => $firstname, 'email' => $email, 'subject' => $subject, 'message' => $message_body];
     $rules = ['lastname' => 'required', 'firstname' => 'required', 'email' => 'required|email', 'subject' => 'required', 'message' => 'required'];
     $messages = ['lastname.required' => 'contactForm.lastname_required', 'firstname.required' => 'contactForm.firstname_required', 'email.required' => 'contactForm.email_required', 'email.email' => 'contactForm.email_invalid', 'subject.required' => 'contactForm.subject_required', 'message.required' => 'contactForm.message_required'];
     // Data Validation
     $validator = Validator::make($inputs, $rules, $messages);
     if ($validator->fails()) {
         $messages = $validator->messages();
         $this->page["inputs"] = $inputs;
         $this->page["messages"] = $messages;
         return;
     }
     $data = compact('firstname', 'lastname', 'email', 'subject', 'message_body');
     $is_mail_sent = Mail::send('algad.bootstrap::mail.contactform.message', $data, function ($message) use($firstname, $lastname, $email) {
         $message->from($email, $firstname . " " . $lastname);
         $message->addReplyTo($email, $lastname . ' ' . $firstname);
         $message->to($this->getProperty('recipient_email'));
     });
     if ($is_mail_sent) {
         $this->page["contact_success_message"] = $this->getProperty('email_sent_confirmation');
     } else {
         $this->page["contact_error_message"] = $this->getProperty('email_sent_failed');
     }
 }
开发者ID:janusnic,项目名称:OctoberCMS-Bootstrap,代码行数:32,代码来源:ContactForm.php

示例9: postRegister

 public function postRegister()
 {
     $rules = ['email' => 'required|email', 'ngo-name' => 'required|min:5', 'ngo-desc' => 'string|min:20', 'ngo-email' => 'required|email', 'ngo-phone' => 'required|min:7'];
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return redirect('/envy/auth/register')->withErrors($validator)->withInput();
     } else {
         $user = User::where('user_email', Input::get('email'))->first();
         if ($user && !$user->is_user_ngo) {
             $user->is_user_ngo = true;
             $user->save();
             $ngo = new Ngo();
             $ngo->user_id = $user->user_id;
             $ngo->ngo_name = Input::get('ngo-name');
             $ngo->ngo_email = Input::get('ngo-email');
             $ngo->ngo_phone = Input::get('ngo-phone');
             $ngo->ngo_description = Input::get('ngo-desc');
             $ngo->save();
         }
         // $user = new User;
         // $user->user_name = Input::get('name');
         // $user->user_email = Input::get('email');
         // $user->password = Hash::make(Input::get('password'));
         // $user->is_user_ngo = true;
         // $user->save();
         return redirect('/envy/auth/login');
     }
 }
开发者ID:umarhussain15,项目名称:web_semester_project_integration_repo_Jan16,代码行数:28,代码来源:MyAuthController.php

示例10: postCreate

 public function postCreate()
 {
     $validator = Validator::make(Input::all(), Order::$rules);
     if ($validator->passes()) {
         $order = new Order();
         $order->user_id = Auth::id();
         $order->delivery_address = Input::get('delivery_address');
         $order->sum = Cart::total();
         $order->payment_type = Input::get('payment_type');
         $order->save();
         foreach (Cart::content() as $cart_item) {
             $order_product = new OrderProduct();
             $order_product->order_id = $order->id;
             $order_product->product_id = $cart_item->id;
             $order_product->qty = $cart_item->qty;
             $order_product->sum = $cart_item->price;
             $order_product->save();
         }
         Cart::destroy();
         if ($order->payment_type == 0) {
             //pay card
             return Redirect::to('order/pay');
         }
         return Redirect::to('cart/confirmed')->with('message', 'Заказ оформлен.');
     }
     return Redirect::to('cart/confirm')->with('message', 'Проверьте корректность заполнения полей!')->withErrors($validator)->withInput();
 }
开发者ID:venomir,项目名称:tc,代码行数:27,代码来源:OrderController.php

示例11: postEdit

 public function postEdit(Request $request)
 {
     $validator = Validator::make($request->all(), ['first_name' => 'required', 'last_name' => 'required', 'gender' => ['required', 'in:male,female'], 'password' => 'min:6', 'martial_status' => ['in:single,engaged,married']]);
     if ($validator->fails()) {
         return redirect()->back()->withInput()->withErrors($validator);
     }
     if ($request->has('password') && $request->has('password_confirmation')) {
         if ($request->password === $request->password_confirmation) {
             Auth::user()->password = Hash::make($request->password);
             Auth::user()->save();
         } else {
             return redirect()->back()->withInput()->with('errors', ['Passwords does not match.']);
         }
     }
     $user = Auth::user();
     $user->first_name = $request->first_name;
     $user->last_name = $request->last_name;
     $user->gender = $request->gender;
     $user->birth_date = $request->has('birth_date') ? $request->birth_date : null;
     $user->phone = $request->has('phone') ? $request->phone : null;
     $user->bio = $request->has('bio') ? $request->bio : null;
     $user->marital_status = $request->has('marital_status') ? $request->marital_status : null;
     $user->save();
     return redirect()->route('profile.edit')->with('info', 'your profile has been updated');
 }
开发者ID:KareemBadawy,项目名称:Flarian,代码行数:25,代码来源:ProfileController.php

示例12: create

 public function create()
 {
     $p = new Post();
     $inputs = \Input::all();
     $rules = array('title' => 'required', 'metadescription' => 'required', 'content' => 'required', 'tags' => 'required', 'photo' => 'required', 'category' => 'required');
     $validation = Validator::make($inputs, $rules);
     if ($validation->fails()) {
         return var_dump($validation->errors());
     } else {
         $p->title = \Input::get('title');
         $p->metadescription = \Input::get('metadescription');
         $p->content = \Input::get('content');
         $p->tags = \Input::get('tags');
         $p->category = \Input::get('category');
         //		$p->photo = \Input::get('photo');
         if ($file = \Input::file('photo')) {
             //getting timestamp
             $timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
             $name = $timestamp . '-' . $file->getClientOriginalName();
             $file->move(public_path() . '/uploads/', $name);
             $p->photo = '/uploads/' . $name;
         } else {
             return 'Pic Not uploaded Properly! Press Back Button';
         }
         $p->save();
         return \Redirect::route('adminsite')->with('alert', 'Publication created successfully!');
     }
 }
开发者ID:devasanibharath,项目名称:Laravel-Complete-blog,代码行数:28,代码来源:AdminController.php

示例13: adAnnounce

 public function adAnnounce(Request $request)
 {
     $data = ["name" => $request->name, "email" => $request->email, "phone" => $request->phone, "description" => $request->description, "chambres" => $request->chambres, "pieces" => $request->pieces, "surface" => $request->surface, "prix" => $request->prix, "aid" => $request->aid];
     $file = null;
     $data["email"] = $request->email;
     $input = array('image' => Input::file('image'));
     $rules = array('image' => 'image');
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return response()->json(['data' => 'Fichier invalid', 'state' => false]);
     } else {
         if ($request->hasFile('image')) {
             $file = $request->file('image');
             $filename = $file->getClientOriginalName();
             $destinationPath = public_path() . '/uploads/ad';
             $file->move($destinationPath, $filename);
             $data['image'] = asset('uploads/ad/' . $filename);
             $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
             $collection = new \MongoDB\Collection($manager, 'builders', 'ads');
             $stat = ['email' => $request->email, 'data' => $data, 'created' => new \DateTime("now")];
             try {
                 $collection->insertOne($stat);
             } catch (\Exception $e) {
                 return response()->json(['state' => false]);
             }
             return response()->json(['data' => $data, 'state' => true]);
         }
     }
 }
开发者ID:Symfomany,项目名称:laravelcinema,代码行数:29,代码来源:AdController.php

示例14: update

 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $validacao = Validator::make($request->all(), ['nome_site' => 'required|string', 'logo' => 'image|mimes:jpg,jpeg,png,gif', 'logo_footer' => 'image|mimes:jpg,jpeg,png,gif']);
     if ($validacao->fails()) {
         return redirect('admin/configuracoes/site')->withErrors($validacao)->withInput();
     } else {
         try {
             $config = Configuracao::find($id);
             $config->nome_site = $request->nome_site;
             if ($request->hasFile('logo')) {
                 if ($request->file('logo')->isValid()) {
                     $nomeOriginal = $request->file('logo')->getClientOriginalName();
                     $novoNome = md5(uniqid($nomeOriginal)) . '.' . $request->file('logo')->getClientOriginalExtension();
                     $request->file('logo')->move('uploads/logo', $novoNome);
                     $config->logo = $novoNome;
                 }
             }
             if ($request->hasFile('logo_footer')) {
                 if ($request->file('logo_footer')->isValid()) {
                     $nomeOriginal = $request->file('logo_footer')->getClientOriginalName();
                     $novoNome = md5(uniqid($nomeOriginal)) . '.' . $request->file('logo_footer')->getClientOriginalExtension();
                     $request->file('logo_footer')->move('uploads/logo', $novoNome);
                     $config->logo_footer = $novoNome;
                 }
             }
             $config->save();
             session()->flash('flash_message', 'Registro atualizado com sucesso!');
         } catch (\Exception $e) {
             LogR::exception($config, $e);
             session()->flash('flash_message', 'Ops!! Ocorreu algum problema!. ' . $e->getMessage());
         }
         return Redirect::back();
     }
 }
开发者ID:safaricco,项目名称:admfw,代码行数:41,代码来源:Configuracoes.php

示例15: login

 public function login(Request $request)
 {
     $input = $request->json()->all();
     $validator = Validator::make($input, ['email' => 'required|email', 'password' => 'required', 'deviceId' => 'required']);
     if ($validator->fails()) {
         $error = $validator->errors()->all();
         return response()->json(['errorMessage' => [$error]], 404);
     }
     $deviceId = $input['deviceId'];
     $result = DB::table('users')->where('email', $input['email'])->first();
     if ($result && Hash::check($input['password'], $result->password)) {
         $res = DB::table('tokens')->where('deviceId', $deviceId)->first();
         if ($res) {
             $token = Token::find($res->id);
             $token->token = bin2hex(openssl_random_pseudo_bytes(64));
             $token->save();
         } else {
             DB::table('tokens')->insert(['token' => bin2hex(openssl_random_pseudo_bytes(64)), 'userId' => $result->id, 'deviceId' => $deviceId]);
         }
         $token = DB::table('tokens')->select('token')->where('userId', $result->id)->where('deviceId', $deviceId)->first();
         if ($token) {
             return response()->json($token);
         } else {
             return response()->json(['errorMessage' => 'login failed'], 404);
         }
     } else {
         return response()->json(['errorMessage' => 'this user not found'], 404);
     }
 }
开发者ID:48group,项目名称:Eastland-Server-Side,代码行数:29,代码来源:UserController.php


注:本文中的Illuminate\Support\Facades\Validator::make方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。