Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$e->getMessage() #21

Open
gustavosobrinho01 opened this issue Jul 14, 2016 · 5 comments
Open

$e->getMessage() #21

gustavosobrinho01 opened this issue Jul 14, 2016 · 5 comments

Comments

@gustavosobrinho01
Copy link

I am using the package and run $ e- > getMessage ( ) , I come across " "
If you run $ e- > getMessageBag ( ) , run into return without customization

@tookit
Copy link

tookit commented Aug 9, 2016

I have the same problem

@blogui91
Copy link

@gugasobrinho @tookit I had the same issue, Taking a look into the package in the file LaravelValidator,php there is a function Passes which never receives an array of custom messages, I just have overriden it in my entity validator (in my case SkillValidator) with the difference this time i am giving messages array.

  <?php

namespace App\Modules\Validators;

use \Prettus\Validator\Contracts\ValidatorInterface;
use \Prettus\Validator\LaravelValidator;

class SkillValidator extends LaravelValidator
{

    protected $rules = [
        ValidatorInterface::RULE_CREATE => ['name' => 'required'],
        ValidatorInterface::RULE_UPDATE => [],
   ];

   protected $messages = [
    'name.required' => 'El campo titulo  es un campo requerido'
   ];


     /**
     * Pass the data and the rules to the validator
     *
     * @param string $action
     * @return bool
     */
    public function passes($action = null)
    {
        $rules     = $this->getRules($action);
        $validator = $this->validator->make($this->data, $rules,$this->messages);

        if( $validator->fails() )
        {
            $this->errors = $validator->messages();
            return false;
        }

        return true;
    }
}

I hope it may help you. :)

@ricardofilho6
Copy link

This still does not work, when i use $e->getMessage() returns {"error":true,"message":""}

@touchinformatica
Copy link

Use getMessageBag method instead getMessage:

return response()->json(['error' => $e->getMessageBag()], 500);

@ricardofilho6
Copy link

MessageBag returns =>
MessageBag {#558 #messages: array:1 [ "fk_employee" => array:1 [ 0 => "validation.unique" ] ] #format: ":message"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants