Support the ongoing development of Laravel.io →
Forms Validation

Hello, i have a code like this

if ($validation->fails()) {
    foreach ($validation->messages()->all() as $message) {
        Flash::error($message);
    }
    return Redirect::back()->withInput();
}

and i am using this code almost every form validation. Instead of writing (or copy/paste) this code all the time i want to make a own class which can be called from everywhere of my project. I created my class folder under the app folder and added it to global.php and its working awesome.

but when i create a static function like this insede my Helper class

class Helper {

    public static function FlashValidationMessage($validation) {

        if ($validation->fails()) {
            foreach ($validation->messages()->all() as $message) {
                Flash::error($message);
            }
            return Redirect::back()->withInput();
        }
    }

}

and put this code inside the controller

return Helper::FlashValidationMessage($validation);

when validation fails everything works great, but when validation passes function returns nothing so i see only a white blank screen.

What are your suggestion to work this function properly? Maybe i need another clever approach.

Thanks for the replies.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ekeloglu ekeloglu Joined 22 Oct 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.