本文整理汇总了PHP中Illuminate\Support\MessageBag类的典型用法代码示例。如果您正苦于以下问题:PHP MessageBag类的具体用法?PHP MessageBag怎么用?PHP MessageBag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MessageBag类的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);
}
示例2: postIndex
public function postIndex()
{
$form = Form::fromFile(__DIR__ . '/contact.form.php');
$form->setInput(Input::all());
$validator = $form->accept();
if ($validator->fails()) {
$form->setErrors($validator->messages());
return View::make('contact')->with('form', $form);
}
$data = $validator->getData();
// Get the label for an enum
$data['found'] = $form->fieldSpec('found')['options'][$data['found']];
// Parse date inputs
$data['from_date'] = strtotime($data['from_date']);
$data['to_date'] = strtotime($data['to_date']);
if (!Mail::send('emails.contact', $data, function ($message) use($data) {
$message->to('contact@example.com')->replyTo($data['email'], $data['person'])->subject('Contact form')->setCharset('UTF-8');
})) {
$errors = new MessageBag();
// global here can be anything that's not an actual field name
$errors->add('global', 'Could not send your contact request to contact@example.com. Please try again later.');
return View::make('contact')->with('form', $form)->with('errors', $errors);
}
return View::make('success');
}
示例3: login
public function login(Request $request)
{
if (!empty($request->input('email'))) {
$email = $request->input('email');
$password = $request->input('password');
$user_node = $this->users->getUser($email);
// Create the Person model
$user = new Person();
$user->setNode($user_node);
if (!empty($user_node)) {
// Check password and verification
if (!$user->verified) {
$message_bag = new MessageBag();
return redirect()->back()->with('errors', $message_bag->add('email', 'Dit emailadres is nog niet geverifieerd.'));
} elseif (Hash::check($password, $user->password)) {
Auth::login($user);
// Register the event to Piwik
$this->registerPiwikEvent($user->email, 'Login');
return redirect($this->redirectTo);
} else {
$message_bag = new MessageBag();
return redirect()->back()->with('errors', $message_bag->add('password', 'Het wachtwoord is incorrect.'));
}
} else {
$message_bag = new MessageBag();
return redirect()->back()->with('errors', $message_bag->add('email', 'Het emailadres werd niet gevonden.'));
}
} else {
$message_bag = new MessageBag();
return redirect()->back()->with('errors', $message_bag->add('email', 'Het emailadres werd niet gevonden.'));
}
}
示例4: 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;
}
示例5: 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;
}
示例6: storeCourse
public static function storeCourse()
{
/**Запись и сохранение курса
* в случае удачи - возвращаем true,иначе false
* @return BooleanType
* */
//Проверка радостей от пользователя
$validator = Validator::make(array('name' => Input::get('name')), array('name' => array('required', 'min:5')));
if ($validator->passes()) {
dd($validator);
//Прошла валидация
$course = new Course();
$course->name = Input::get('name');
$course->save();
//т.к у нас тепреь есть новая модель,
//но контроллеры о ней ничего еще не знают-
//положим упоминание о ней в Message Bag,чтоб они смогли прочитать
$messageBag = new MessageBag();
$messageBag->add('courseId', $course->id);
$message = 'Course ' . $course->name . ' been successful created';
$status = 'success';
$result = true;
} else {
//Все немного хуже и данные не валидны
$message = 'Course not been successful created';
$status = 'fail';
$result = false;
}
//Вложим в сессию итог действия
Session::put('message', $message);
Session::put('status', $status);
return $result;
}
示例7: sendPass
public function sendPass()
{
$input = Input::all();
$user = User::where('email', '=', $input['email'])->first();
$errors = new MessageBag();
if ($user) {
try {
$user = $user->toArray();
$data['username'] = $user['username'];
$data['token'] = $input['_token'];
$data['firstname'] = $user['firstname'];
$data['lastname'] = $user['lastname'];
$data['email'] = $user['email'];
Session::put('data', $data);
Mail::send('mail.reset_' . App::getLocale(), $data, function ($message) {
$message->to(session('data')['email'], session('data')['firstname'], session('data')['lastname'])->subject(trans('login.forgot'));
});
DB::insert('INSERT INTO password_resets (email, token, created_at) values ' . '("' . $data['email'] . '", "' . $data['token'] . '", "' . time() . '")');
} catch (Exception $e) {
$errors->add('reset', trans('message.trans'));
return redirect()->back()->withErrors($errors);
}
Session::pull('data');
return redirect('login')->withErrors(['sent' => trans('message.sent')]);
} else {
Session::pull('data');
$errors->add('email', trans('message.email'));
return redirect()->back()->withErrors($errors);
}
}
示例8: 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;
}
}
示例9: veritranscc
/**
* Veritrans Credit Card
*
* 1. Check Order
* 2. Save Payment
*
* @return Response
*/
public function veritranscc()
{
if (!Input::has('order_id')) {
return new JSend('error', (array) Input::all(), 'Tidak ada data order id.');
}
$errors = new MessageBag();
DB::beginTransaction();
//1. Validate Sale Parameter
$order = Input::only('order_id', 'gross_amount', 'payment_type', 'masked_card', 'transaction_id');
//1a. Get original data
$sale_data = \App\Models\Sale::findorfail($order['order_id']);
//2. Save Payment
$paid_data = new \App\Models\Payment();
$payment['transaction_id'] = $sale_data['id'];
$payment['method'] = $order['payment_type'];
$payment['destination'] = 'Veritrans';
$payment['account_name'] = $order['masked_card'];
$payment['account_number'] = $order['transaction_id'];
$payment['ondate'] = \Carbon\Carbon::parse($order['transaction_time'])->format('Y-m-d H:i:s');
$payment['amount'] = $order['gross_amount'];
$paid_data = $paid_data->fill($payment);
if (!$paid_data->save()) {
$errors->add('Log', $paid_data->getError());
}
if ($errors->count()) {
DB::rollback();
return response()->json(new JSend('error', (array) Input::all(), $errors), 404);
}
DB::commit();
$final_sale = \App\Models\Sale::id($sale_data['id'])->with(['voucher', 'transactionlogs', 'user', 'transactiondetails', 'transactiondetails.varian', 'transactiondetails.varian.product', 'paidpointlogs', 'payment', 'shipment', 'shipment.address', 'shipment.courier', 'transactionextensions', 'transactionextensions.productextension'])->first()->toArray();
return response()->json(new JSend('success', (array) $final_sale), 200);
}
示例10: 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()]);
}
示例11: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$error = '';
/* $track = resi::select('resi.noresi','k.nama AS konsumen',
'ca.nama AS asal','ct.nama AS tujuan',
'b.tglberangkat',//'b.jamberangkat',
'b.tgltiba',
'b.nopolisi','ps.nama AS sopir','pk.nama AS kenek',
'u.name AS user',
'resi.status')
->leftJoin('konsumen as k','k.idkonsumen','=','resi.idkonsumen')
->leftJoin('berangkat as b','b.idberangkat','=','resi.idberangkat')
->leftJoin('cabang as ca','ca.idcabang','=','b.idasal')
->leftJoin('cabang as ct','ct.idcabang','=','b.idtujuan')
->leftJoin('pegawai as ps','ps.idpegawai','=','b.idsopir')
->leftJoin('pegawai as pk','pk.idpegawai','=','b.idkenek')
->leftJoin('users as u','u.id','=','resi.user')
->where('resi.noresi','=',Request::get('id'))->get();
//*/
$resi = resi::find(Request::get('id'));
if (!$resi) {
$error = new MessageBag();
$error->add('notfound', 'Maaf resi dengan nomer ' . Request::get('id') . ' tidak ditemukan');
return view('master')->with('track', true)->withErrors($error);
} else {
$data = resi::select('resi.idberangkat', 'resi.idrute', 'resi.noresi', 'tk.nama as prspengirim', 'tk.cp as cppengirim', 'rk.nama as prspenerima', 'rk.cp as cppenerima', 'tc.nama as cabangasal', 'rc.nama as cabangtujuan', 'berangkat.nopolisi', 'berangkat.supir1', 'berangkat.supir2', 'rute.tglbrkt', 'rute.tgltiba')->leftJoin('konsumen AS tk', 'tk.idkonsumen', '=', 'resi.idkonsumen')->leftJoin('konsumen AS rk', 'rk.idkonsumen', '=', 'resi.idpenerima')->leftJoin('rute', function ($join) {
$join->on('rute.sjt', '=', 'resi.idberangkat');
$join->on('rute.id', '=', 'resi.idrute');
})->leftJoin('cabang AS tc', 'tc.idcabang', '=', 'rute.kotamuat')->leftJoin('cabang AS rc', 'rc.idcabang', '=', 'rute.kotabongkar')->leftJoin('berangkat', 'berangkat.idberangkat', '=', 'rute.sjt')->where('resi.noresi', Request::get('id'))->first();
$posisi = posisiarmada::where('sjt', $data->idberangkat)->where('id', $data->idrute)->get();
return view('master')->with('track', true)->with('data', $data)->with('posisi', $posisi);
}
//('errorstracking',$error);
}
示例12: delete
public function delete()
{
$rules = array('newsletter_unsubscribe_email' => 'required|max:250|email|exists:fbf_newsletter_signups,email');
$validator = \Validator::make(\Input::all(), $rules, \Lang::get('laravel-newsletter-signup::copy.unsubscribe.validation'));
if ($validator->fails()) {
if (\Request::ajax()) {
$messages = $validator->messages();
$message = $messages->first('newsletter_unsubscribe_email');
return \Response::JSON(array('message' => $message), 400);
}
return \Redirect::to(\Input::get('from'))->withInput()->withErrors($validator);
}
$signup = Signup::withTrashed()->where('email', '=', \Input::get('newsletter_unsubscribe_email'))->first();
if ($signup->trashed()) {
if (\Request::ajax()) {
return \Response::JSON(array('message' => \Lang::get('laravel-newsletter-signup::copy.unsubscribe.already_unsubscribed')), 400);
}
$message = new MessageBag();
$message->add('newsletter_unsubscribe_email', \Lang::get('laravel-newsletter-signup::copy.unsubscribe.already_unsubscribed'));
return \Redirect::to(\Input::get('from'))->withInput()->with('errors', $message);
}
$signup->delete();
$success = \Lang::get('laravel-newsletter-signup::copy.unsubscribe.success');
if (\Request::ajax()) {
return \Response::JSON(array('message' => $success));
}
return \Redirect::to(\Input::get('from'))->with('newsletter_unsubscribe_email_message', $success);
}
示例13: 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'));
}
示例14: getAuthState
public function getAuthState()
{
$state = new JobAuthState();
$state->authMechanism = self::AUTH_MECHANISM;
if (!Input::has('access_token')) {
return $state;
}
$ownerId = $this->authServer->getResourceOwnerId();
$type = $this->authServer->getResourceOwnerType();
if ($type == 'user') {
//oAuth token belongs to a user
$user = User::find($ownerId);
$actAs = $user->id;
if (Input::has('act_as')) {
if ($user->hasRole(UserRole::ACTOR_ROLE)) {
$actAs = Input::get('act_as');
} else {
$bag = new MessageBag();
$bag->add('authorisation', 'The current user cannot act as another user');
throw new AuthorisationException($bag);
}
}
$state->userId = $user->id;
$state->rememberMe = false;
$state->actingUserId = $actAs;
} else {
//oAuth token belongs to a client
//$client = OAuthClient::find($ownerId);
//There is no user context and act_as shouldn't be needed as clients can use
//access tokens if they want to execute as a user
}
return $state;
}
示例15: 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;
}