Laravel Community Tools by Tighten

Md. Asif Rahman

Joined: 5 years ago
Total tricks: 3
Last trick: 4 years ago

Submitted tricks

if you want to run custom validation having a long function in laravel request file, you can use the following tricks to get the things done using withValidator method.
asifzcpe 5 years ago 20872
5.5
If you only need the functionality of a custom rule once throughout your application, you may use a Closure instead of a rule object. The Closure receives the attribute's name, the attribute's value, and a $fail callback that should be called if validation fails. Below is the code example:
asifzcpe 5 years ago 21062
We have already known the usage of accessors and mutators. We use accessors in laravel model to modify any field data while retrieving the records and mutators to modify any field data while inserting to database. So, to modify any field before, we needed two separate methods for a single filed i.e. one method for accessor and one for mutator but in latest laravel release I mean in laravel 8.77.0, we can use a single method for both accessor and mutator using closure . Given below is the syntax for single mehtod accessor and mutator:
asifzcpe 4 years ago 34570