Laravel - Get error message from localized file - laravel

I'm creating my own validation and need to retrieve error messages from the localized file(resources/lang/en/validation.php and etc). The main task is to get array of error messages from the appropriate file. Usually, the validator does it and you don't need to worry about it. Does exist a way to get all these messages with no using validator?

You can access your translation files and their contents from anywhere with the global helper function trans
For example: your translations are in the file resources/lang/en/customvalidation.php
return [
'customerror' => 'my custom error message',
];
Then
trans('customvalidation.customerror')
will return "my custom error message" (depending on the current set language)

Related

Change error system message in oracle apex

I have a form page and all field is required when press save the below message appear
How i can change this message to custom message "please fill all required fields " , and how i can clear error when enter value (when value change to not null).
I can't see images at the moment.
However, one option might be to create your own validation which returns error text. Something like
if :P1_NAME is null then
return ('Name must be entered');
end if;
Messages are automatically cleared once you submit the page and there are no errors left.
I am not sure if you can change system messages but you can add custom error messages with javascript if a change happens in any item.
Add a change event to the item that runs javascript and use the following code:
var item = apex.item('P1_ITEM').getValue();
if(item == null) {
//First clear the errors
apex.message.clearErrors();
// Now show new errors
apex.message.showErrors([
{
type: "error",
location: [ "page", "inline" ],
pageItem: "P1_ITEM",
message: "Name is required!",
unsafe: false
},
{
type: "error",
location: "page",
message: "Page error has occurred!",
unsafe: false
}
]);
}
However, this will not stop the user from submitting, it only allows you to better display the messages, so you must add the corresponding validations after submit.
If you want to remove the system error message from the required items, you can disable the option of Value Required on item and add a custom validation as they told you in the other response.
If you want to explore all the apex.message options better, I recommend this documentation:
https://docs.oracle.com/database/apex-5.1/AEAPI/apex-message-namespace.htm#AEAPI-GUID-D15040D1-6B1A-4267-8DF7-B645ED1FDA46
More documentation for apex.item:
https://docs.oracle.com/cd/E71588_01/AEAPI/apex-item.htm#AEAPI29448
There are some ways for how to do such things.
Firstly you have the custom Validations you can make, these are awesome and you should really try to use them if possible.
Then there is also the Error message on the saving procedure, but this just throws a custom message on procedure fail so I never use it.
What you appear to be seeing there is that you got an error message and didnt change the fields associated with the error.
If the save procedure is custom, you can also put in an EXCEPTION block before the END, and catch errors there and throw out a custom error with a custom error message.
Another thing I really like is to actually rename some common errors so I dont have to catch them all individually. Say clients may often times try to save identical data, thus breaking the PK. Oracle will throw an error, but the message is good for the developer, but less understandable for the client whom I always assume is a 3 year old kid who can barely read and will cry over everything. So I make an error handling function, add it to apex, and so when the error occurs, it throws a nice message informing the client that they have tried to add some data that already exists.
So, an error handling function associated with APEX, to rename some normal errors.
Good luck

How to properly use the CI-Merchant library's config file

I am trying to add items to merchant.php (the CI-Merchant library's config file, which I believe is auto-loaded by CodeIgniter). I want to be able to set the settings for the payment gateway (driver) I am choosing in the settings so that I don't have to write it out in every controller that is calling the library/driver and I do not want to hardcode the settings in the driver.
These are the settings I am trying to save, but I could have others with different gateways:
$config['authorize_net']['api_login_id'] = '***';
$config['authorize_net']['transaction_key'] = '***';
$config['authorize_net']['test_mode'] = TRUE;
$config['authorize_net']['developer_mode'] = TRUE;
However this is causing 2 warnings. The first:
A PHP Error was encountered
Severity: Warning
Message: stripos() expects parameter 1 to be string, array given
Filename: libraries/merchant.php
Line Number: 97
And the second:
A PHP Error was encountered
Severity: Warning
Message: strtolower() expects parameter 1 to be string, array given
Filename: libraries/merchant.php
Line Number: 103
So it seems to me that CodeIgniter is automatically passing the merchant.php config file to the library but it was not expecting it (which also confuses me, because in the CI-Merchant download it comes with the config file).
My worst case scenario would be to change the "default settings" in merchant_authorize_net.php the but I really want to avoid this, below is what that default settings function looks like.
public function default_settings()
{
return array(
'api_login_id' => '',
'transaction_key' => '',
'test_mode' => FALSE,
'developer_mode' => FALSE,
);
}
My questions are:
Is there a proper way to use the CI-Merchant's config file?
If not, is there a way to have driver-specific config files in CodeIgniter?
The config file is actually just there as boilerplate code which should probably be removed. CI-merchant itself doesn't have any logic to automatically read the config file for you.
Generally the recommended approach is to store the settings in your own config file (or environment variables), and then use those settings in your controller to initialize the library. You are correct that it's best to try and avoid editing anything inside the library folder.
If you are starting a new project I also recommend you check out Omnipay, the successor to CI-Merchant, as CI-Merchant will not be receiving any further development.

Peoplecode function not working

I am using Peoplecode which is a Peoplesoft coding language.
I am trying to access JUST the 'message text' from a message catalog.
It pulls the correct number 7373 when I use the same code on another page.
But in this instance it returns the message
'GetMessageText: No default message. (2012,2012)'.
Here is the code I am using..
&cur_year = Year(%Date);
&MsgNum = MsgGetText(2012, 2012, "");
It's because it can't find the message (2012,2012). You have to specify the correct message set and message number to retrieve from the message catalog.
Look here:
http://docs.oracle.com/cd/E28394_01/pt852pbh1/eng/psbooks/tpcl/book.htm?File=tpcl/htm/tpcl02.htm%2337ee99c9453fb39_ef90c_10c791ddc07__3cd3

Get [Messages] values in InnoSetup's language file

I know I can easily get messages inside
[CustomMessages]
AdditionalIcons=blablabla
using this code:
ExpandConstant('{cm:AdditionalIcons}');
which gets the AdditionalIcons string message. However, how can I get messages inside this?
[Messages]
ButtonNext=huhu
ButtonInstall=bubu
What I need is to get the ButtonNext, ButtonInstall and other values, and it is NOT possible to get those values using code like this:
ExpandConstant('{cm:ButtonNext}');
How can I query those values?
Related links
Inno Setup Script tips
Try
SetupMessage(msgButtonNext);
In general, the name of the constant to use (in this case msgButtonNext) is msg + the name of the message (string concatination).

Implementing Database Error Handling in CodeIgniter

I am creating a webapp using codeigniter. I want to implement a error handling function. Say for example if I call a method of a model, and if an error occurs in that method, the error handler comes into action to return some pre-formatted string.
I was thinking of creating something like MY_Model, which every model class extends. Then, I can add the error handler in MY_Model class. But whether this can be done is beyond me right now. (yes I am a newbie at this)
Any enlightening ideas will help.
Regards
What I tend to do is return an array instead of a boolean. This array contains 2 keys, 'return' and 'error'.
In case of an error this array will look like the following:
array('return' => FALSE, 'error' => 'Some error')
In case of a successful execution this array will look like the following:
array('return' => TRUE)
The controller then verifies these results and if there's an error it will display the one set in the 'error' key.

Resources