Home > front end >  How do I display my error message as a link in Laravel
How do I display my error message as a link in Laravel

Time:04-14

I'm trying to create a validation such that if model_name is not unique, it will display a html link to view the existing model_name row. Something like this image, however my current code displays the message like this. What do I have to change in my code? Here's my code validation code:

'model_name.unique'=>'Model Already exists. <a href="'.route('view.models',[$request->model_name]).'">Go to page.</a>',

Thanks for any help.

Edit:

Here's the error part of my form:

<input type="text" name="model_name"  id="exampleFormControlInput1" placeholder="Model Name">
                    @error('model_name')
                    <span >{{ $message }}</span>
                    @enderror
                   </div>

CodePudding user response:

That escaped character. You can know more about it here and Laravel Docs.

So to be quick, you can try:

<input type="text" name="model_name"  id="exampleFormControlInput1" placeholder="Model Name">
                @error('model_name')
                <span >{!! $message !!}</span>
                @enderror
               </div>

CodePudding user response:

Pass the error like this in your blade file:

@error ('model_name')
  <span >{!! $message !!}</span>
@enderror

That ensure the link is parsed correctly, right now it's being escaped. Check this for examples

  • Related