Skip to content
Advertisement

Include extra validation in Laravel 8 using $errors Variable

I have a store Method for my TransactionController, at the moment it does validate that the required information is received (standard Laravel validation), nonetheless, it can’t check if the value received exists on a third table (since it’s a foreign key).

Store method of TransactionController.php

JavaScript

I want to add further validation to ensure that the information received is ready for get stored in the database and if it is not, inform the user with a custom message.

This is done with:

TransactionController.php store Method

JavaScript

How can I return back to the view sending my custom error message in the else clause?

Advertisement

Answer

You can add custom validation for this instead of if else

JavaScript

Ref:https://laravel.com/docs/8.x/validation#custom-validation-rules

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement