Including HTML in Blade

Viewed 43

I have written this code here in the controller when an admin wants to delete a drug:

 $msg = 'You are not authorized to delete this drug the drug belongs to ,<a href="'. action('UserController@viewStore',$drug->drugStore->id) . '"> {{$drug->drugStore->name}}</a>';
            return redirect()->back()->with('error', $msg);

In the other Blade file I have this session alert:

@if(session()->has('error'))
    <div class="alert alert-danger alert-dismissible fade show" role="alert">
        <strong>Wrong!</strong> {!!session('error')!!}.
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">×</span>
        </button>
    </div>
@endif

The href is being successfully created but I am trying to add {{$drug->drugStore->name}} but is keep taking it as a plain text.

The alert that is being shown:

Wrong! You are not authorized to delete this drug the drug belongs to , {{$drug->drugStore->name}}.

1 Answers

The {{ $var }} syntax is only for use in Blade files.

In your controller, you should be using standard PHP concatenation:

$msg = 'You .... to <a href="'. action('UserController@viewStore', $drug->drugStore->id) . '">' . $drug->drugStore->name . '</a>';
//                                                                                            ^^^^                      ^^^^
Related