ardent icon indicating copy to clipboard operation
ardent copied to clipboard

please help me on setting custom attributes and getting error message

Open saurovh opened this issue 10 years ago • 1 comments

First following code is showing setAttributeNames method not exist

and is that the right way of getting error messages

      $permission = new Permission();
       $permission->display_name = Input::get('display_name');
       $permission->name = Input::get('name');
       $permission->setAttributeNames(array(
                     'display_name'   => trans('permission.display_name'),
                'name'   => trans('permission.permission_key')
          ));
       $json = array();
       if($permission->save()){

         $this->setErrorMessage('success',sprintf(trans("messages.success_insert"),trans('common.text_user')));
         $json['redirect'] = action('RolesAndPermissionController@indexPermissions');

       }else{

      $messages = $permission->errors();

         if ($messages->has('display_name')){ $json['error']['display_name']=$messages->first('display_name');}
         if ($messages->has('name')){ $json['error']['name']=$messages->first('name');}
         if(!Request::ajax()){
            $this->setErrorMessage('danger',trans("messages.error_form"));
          return Redirect::action('RolesAndPermissionController@createPermission')->withErrors($validator);
         }
         $json['error']['message'] = trans("messages.error_form");

       }
     if(Request::ajax()){
        return Response::json($json);
     }else{
       return Redirect::action('RolesAndPermissionController@indexPermissions');
     }

saurovh avatar Jun 25 '14 11:06 saurovh

SetAttributeNames() is a function of the Validator class not the model class that is why you are getting an error. Unfortunately, there does not see to be a way to set human friendly names for attributes in Ardent at the moment.

goldysingh avatar Jun 30 '14 21:06 goldysingh