Home » Php » Laravel 5.4 – Error Message Without Form Validation

Laravel 5.4 – Error Message Without Form Validation

Posted by: admin October 26, 2017 Leave a comment


Want to know if I can use the validation error message on Laravel 5.4 with my custom error message that does not include a form validation.

I am making a validation on view user profile that is to make sure only the owner of the id can view the user profile using Gate.

Do I need to create the instance of Validator and do something like on the Laravel docs.

Below are the example of my codes,


public function show(User $user)
    if (\Gate::denies('showUser', $user)) {
        return redirect()->back()
        ->with('status', 'Invalid Access to other User Profile');
        // how to use instead ->withErrors($message); ?

    return view('profiles.update', compact('user'));


@if(count($errors) > 0)
    <div class="alert alert-danger" role="alert">


        @foreach($errors->all() as $error)  

                <li>{{ $error }}</li>           




    <div class='alert alert-success'>
        {!! session('success') !!}

    <div class='alert alert-danger'>
        {!! session('status') !!}