dash
dash

Reputation: 387

Laravel - rename key associative array with the 'as' keyword?

Is there a way to easily rename a key in an associative array without extra complexity?

for example

public function rules()
 {
   return [
    'candidateID' => 'required|number', **as candidate_id**
    'note'        => 'required|string',
   ];
 }

Upvotes: 2

Views: 136

Answers (2)

Prashant Deshmukh.....
Prashant Deshmukh.....

Reputation: 2292

You cab use Customer message for validation where you can return any message you want.

public function messages()
    {
        return [
                'candidateID.required' => 'candidate_id required.',
                'candidateID.number' => 'candidate_id  must be number.',
        ];
    }

Upvotes: 0

VIKAS KATARIYA
VIKAS KATARIYA

Reputation: 6005

Try This exists:table_name,candidate_id'

public function rules()
 {
   return [
    'candidateID' => 'required|number|exists:table_name,candidate_id',
    'note'        => 'required|string',
   ];
 }

Upvotes: 1

Related Questions