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


PHP MessageBag::add方法代码示例

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


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

示例1: add

 /**
  * Add user
  *
  * @param array $user
  * @return boolean
  */
 public function add(array $user)
 {
     $entity = new UserEntity();
     $entity->setData($user);
     $repo = $this->store()->getRepository('user');
     $event = $this->store()->getEvent();
     if ($this->string()->length($event) > 0) {
         $event_after = 'OnBefore' . $this->string()->ucwords($event) . 'Add';
         Event::on($event_after, function ($user) {
             $filter = array('LOGIC' => 'OR', UserEntity::C_LOGIN => $user[UserEntity::C_LOGIN], UserEntity::C_EMAIL => $user[UserEntity::C_EMAIL]);
             $copy = $this->finder()->filter($filter)->get();
             if ($copy !== false) {
                 $error = new MessageBag();
                 if ($copy->getValue(UserEntity::C_LOGIN) === $user[UserEntity::C_LOGIN]) {
                     $error->add(UserEntity::C_LOGIN, $this->trans('user.manager.add.dublicate_login'));
                     throw new ValidateException($error);
                 }
                 if ($copy->getValue(UserEntity::C_EMAIL) === $user[UserEntity::C_EMAIL]) {
                     $error->add(UserEntity::C_EMAIL, $this->trans('user.manager.add.dublicate_email'));
                     throw new ValidateException($error);
                 }
                 $error->add(UserEntity::C_LOGIN, $this->trans('user.manager.add.dublicate_login_or_email'));
                 $error->add(UserEntity::C_EMAIL, $this->trans('user.manager.add.dublicate_login_or_email'));
                 throw new ValidateException($error);
             }
         });
     }
     if ($this->string()->length($event) > 0) {
         $event_after = 'OnAfter' . $this->string()->ucwords($event) . 'Add';
         Event::on($event_after, function () {
             Cache::clearByTags('user');
         });
     }
     return $this->store()->add($repo, $entity);
 }
开发者ID:jarick,项目名称:bx,代码行数:41,代码来源:UserManager.php

示例2: add

 /**
  * @param string $key
  * @param string $message
  */
 public static function add($key, $message)
 {
     if (!isset(self::$_messages)) {
         self::$_messages = new MessageBag();
     }
     self::$_messages->add($key, $message);
 }
开发者ID:web-feet,项目名称:coasterframework,代码行数:11,代码来源:FormMessage.php

示例3: login

 /**
  * Attempt to log in witth the credentials sent through Input
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function login()
 {
     $response = null;
     $identifier_field = Config::get('auth::user_table.login_through_field');
     $password_field = 'password';
     $credentials = [$identifier_field => Input::get($identifier_field), 'password' => Input::get($password_field), 'enabled' => true];
     if (array_key_exists('email', $credentials)) {
         $credentials['email'] = strtolower($credentials['email']);
     }
     $rules = array();
     $rules['password'] = 'required|min:1';
     if (array_key_exists('email', $credentials)) {
         $rules['email'] = 'required|email|exists:' . Config::get('auth::user_table.table_name');
     }
     if (array_key_exists('username', $credentials)) {
         $rules['username'] = 'required|min:1|exists:' . Config::get('auth::user_table.table_name');
     }
     $validator = \Validator::make($credentials, $rules);
     if ($validator->fails()) {
         return Redirect::back()->withInput()->withErrors($validator->errors());
     }
     if (Auth::attempt($credentials, true)) {
         $response = Redirect::intended('/')->with('success');
     } else {
         $errors = new MessageBag();
         if (empty($credentials[$identifier_field])) {
             $errors->add('message', trans('auth::form.login failed'));
         } else {
             $errors->add('message', trans('auth::form.login failed_with_username', ['username' => $credentials[$identifier_field]]));
         }
         $response = Redirect::back()->withInput()->withErrors($errors);
     }
     return $response;
 }
开发者ID:ipunkt,项目名称:auth,代码行数:39,代码来源:LoginController.php

示例4: addMessage

 public function addMessage($key, $message)
 {
     if (!$this->messageBag) {
         $this->messageBag = new MessageBag();
     }
     $this->messageBag->add($key, $message);
 }
开发者ID:escapework,项目名称:laravelhelpers,代码行数:7,代码来源:BaseRepository.php

示例5: saving

 function saving($model)
 {
     $errors = new MessageBag();
     ///////////
     // RULES //
     ///////////
     if (is_null($model->_id)) {
         $id = 0;
     } else {
         $id = $model->_id;
     }
     //////////////
     // VALIDATE //
     //////////////
     $client = Client::key($model->key)->where('_id', '<>', $id)->first();
     if ($client) {
         $errors->add('Key', 'Key must be unique');
     }
     $client = Client::secret($model->key)->where('_id', '<>', $id)->first();
     if ($client) {
         $errors->add('Secret', 'Secret must be unique');
     }
     if ($errors->count()) {
         $model->setErrors($errors);
         return false;
     }
 }
开发者ID:erickmo,项目名称:CapcusAPI,代码行数:27,代码来源:ClientObserver.php

示例6: deleting

 /** 
  * observe Calendar event deleting
  * 1. delete child
  * 2. delete chart
  * 3. delete schedule
  * 4. act, accept or refuse
  * 
  * @param $model
  * @return bool
  */
 public function deleting($model)
 {
     $errors = new MessageBag();
     //1. delete child
     foreach ($model->calendars as $key => $value) {
         if (!$value->delete()) {
             $errors->add('Calendar', $value->getError());
         }
     }
     //2. delete chart
     foreach ($model->follows as $key => $value) {
         if (!$value->delete()) {
             $errors->add('Calendar', $value->getError());
         }
     }
     //3. delete schedule
     foreach ($model->schedules as $key => $value) {
         if (!$value->delete()) {
             $errors->add('Calendar', $value->getError());
         }
     }
     if ($errors->count()) {
         $model['errors'] = $errors;
         return false;
     }
     return true;
 }
开发者ID:ThunderID,项目名称:HRIS-API,代码行数:37,代码来源:CalendarObserver.php

示例7: deleting

 /** 
  * observe organisation event deleting
  * 1. delete branch
  * 2. delete chart
  * 3. delete policy
  * 4. act, accept or refuse
  * 
  * @param $model
  * @return bool
  */
 public function deleting($model)
 {
     $errors = new MessageBag();
     //1. delete branch
     foreach ($model->branches as $key => $value) {
         //2. delete chart
         foreach ($value->charts as $key2 => $value2) {
             if (!$value2->delete()) {
                 $errors->add('Organisation', $value2->getError());
             }
         }
         if (!$value->delete()) {
             $errors->add('Organisation', $value->getError());
         }
     }
     //3. delete policy
     foreach ($model->policies as $key => $value) {
         if (!$value->delete()) {
             $errors->add('Organisation', $value->getError());
         }
     }
     if ($errors->count()) {
         $model['errors'] = $errors;
         return false;
     }
     return true;
 }
开发者ID:ThunderID,项目名称:HRIS-API,代码行数:37,代码来源:OrganisationObserver.php

示例8: passes

 /**
  * Run the validation on the rules in the array
  * @return boolean
  */
 public function passes()
 {
     $validation = Validator::make($this->data, $this->rules);
     if ($validation->fails()) {
         foreach ($validation->messages()->all() as $error) {
             $this->messages->add('error', $error);
         }
         return false;
     }
     return true;
 }
开发者ID:perryhau,项目名称:laravel-bootstrap,代码行数:15,代码来源:ValidatorBase.php

示例9: isValid

 /**
  * Check that the contents of POST are valid for this model
  * @return boolean
  */
 public function isValid()
 {
     $validation = Validator::make(Input::all(), static::$rules);
     if ($validation->fails()) {
         foreach ($validation->messages()->all() as $error) {
             $this->errors->add('error', $error);
         }
         return false;
     }
     return true;
 }
开发者ID:perezatanaciod,项目名称:ProductCatalog,代码行数:15,代码来源:Entity.php

示例10: testFormatIsRespected

 public function testFormatIsRespected()
 {
     $container = new MessageBag();
     $container->setFormat('<p>:message</p>');
     $container->add('foo', 'bar');
     $container->add('boom', 'baz');
     $this->assertEquals('<p>bar</p>', $container->first('foo'));
     $this->assertEquals(array('<p>bar</p>'), $container->get('foo'));
     $this->assertEquals(array('<p>bar</p>', '<p>baz</p>'), $container->all());
     $this->assertEquals('bar', $container->first('foo', ':message'));
     $this->assertEquals(array('bar'), $container->get('foo', ':message'));
     $this->assertEquals(array('bar', 'baz'), $container->all(':message'));
 }
开发者ID:hochanh,项目名称:Bootsoft-Bowling,代码行数:13,代码来源:MessageBagTest.php

示例11: testRequirements

 public function testRequirements()
 {
     $messages = new MessageBag();
     $requirements = $this->getDefinition()->getAllRequirements();
     foreach ($requirements as $requirement) {
         $requirement = app($requirement);
         if ($requirement->test()) {
             $messages->add('success', $requirement->getSuccess());
         } else {
             $messages->add('error', $requirement->getError());
         }
     }
     return $messages;
 }
开发者ID:illuminate3,项目名称:larastaller,代码行数:14,代码来源:Installer.php

示例12: setPassword

 /**
  * set pasword
  *
  * 1. get activation link
  * 2. validate activation
  * @param activation link
  * @return array of employee
  */
 public function setPassword($activation_link)
 {
     if (!Input::has('activation')) {
         return new JSend('error', (array) Input::all(), 'Tidak ada data activation.');
     }
     $errors = new MessageBag();
     DB::beginTransaction();
     //1. Validate activation Parameter
     $activation = Input::get('activation');
     //1. get activation link
     $employee = Employee::activationlink($activation_link)->first();
     if (!$employee) {
         $errors->add('Activation', 'Invalid activation link');
     }
     //2. validate activation
     $rules = ['password' => 'required|min:8|confirmed'];
     $validator = Validator::make($activation, $rules);
     if ($validator->passes()) {
         $employee->password = $activation['password'];
         $employee->activation_link = '';
         if (!$employee->save()) {
             $errors->add('Activation', $employee->getError());
         }
     } else {
         $errors->add('Activation', $validator->errors());
     }
     if ($errors->count()) {
         DB::rollback();
         return new JSend('error', (array) Input::all(), $errors);
     }
     DB::commit();
     return new JSend('success', ['employee' => $employee->toArray()]);
 }
开发者ID:ThunderID,项目名称:HRIS-API,代码行数:41,代码来源:EmploymentAccountController.php

示例13: logMailErrors

 protected function logMailErrors()
 {
     $this->order->getConnection()->getPdo()->rollback();
     $this->errors->add("email", "There was an error sending the email.");
     Log::error('error sending email.');
     throw new InvalidException();
 }
开发者ID:palmabit,项目名称:catalog,代码行数:7,代码来源:OrderService.php

示例14: index

 public function index()
 {
     Breadcrumbs::addCrumb('Cadastrar', Request::fullUrl());
     $signupForm = new SignupForm(['data' => Input::all(), 'prefix' => 'signup']);
     $errors = new MessageBag();
     if (Input::method() == 'POST') {
         if ($signupForm->isValid()) {
             try {
                 DB::beginTransaction();
                 $user = new User();
                 $user->name = $signupForm->fullName->value;
                 $user->email = $signupForm->email->value;
                 $user->password = Hash::make($signupForm->password->value);
                 if ($user->save()) {
                     Mail::send('user_panel::mails.welcome', ['user' => $user], function ($message) use($user) {
                         $message->to($user->email)->subject('Seja bem vindo');
                     });
                     DB::commit();
                     return Redirect::route('userpanel.signin')->with('success', 'Usuário cadastrado com sucesso!');
                 } else {
                     $errors->add('other', 'Não foi possível cadastrar');
                 }
             } catch (Exception $e) {
                 DB::rollback();
                 throw $e;
             }
         } else {
             $errors = $signupForm->errors();
         }
     }
     return View::make('user_panel::front.register.index', compact('signupForm', 'errors'));
 }
开发者ID:teewebapp,项目名称:user_panel,代码行数:32,代码来源:Register.php

示例15: saving

 /** 
  * observe sale event saving
  * 1. generate ref number
  * 2. generate unique number
  * 3. create transact_at
  * 4. check voucher
  * 5. execute it there was no error
  * 
  * @param $model
  * @return bool
  */
 public function saving($model)
 {
     $errors = new MessageBag();
     //1. Generate ref number
     $model->ref_number = $model->generateRefNumber($model);
     //2. Generate unique number
     if ($model->status == 'cart' || $model->status == 'na') {
         $model->unique_number = $model->generateUniqueNumber($model);
     }
     //3. create transact_at
     if (!in_array($model->status, ['canceled', 'abandoned', 'paid', 'shipping', 'delivered', 'na', 'wait', 'payment_process'])) {
         $model->transact_at = Carbon::now()->format('Y-m-d H:i:s');
     }
     //4. check voucher
     if ($model->voucher_id != 0 && (!$model->voucher()->count() || $model->voucher->type == 'promo_referral')) {
         $errors->add('Voucher', 'Voucher tidak valid.');
     } elseif ($model->voucher()->count()) {
         $result = $model->CountVoucherDiscount($model);
         if (!$result && count($model['errors'])) {
             return false;
         } else {
             $model->voucher_discount = $result;
         }
     }
     if ($errors->count()) {
         $model['errors'] = $errors;
         return false;
     }
     return true;
 }
开发者ID:ThunderID,项目名称:SHOP-API,代码行数:41,代码来源:SaleObserver.php


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