1

I want to display the text in the blade as html. To do this, I used this code in the controller section: ‌

class MessageController{
    public function customText($color): string
    {
        return '<p style="color: '. $color . '"><strong>Lorem</strong> ipsum dolor <img src="images/image.jpg"></p>';
    }

    public function show(){
        return view('1.blade',[
            'message' => $this->customText('#fff')
        ]);
    }
}

Now how can I function the same code above in blade ?

For example, I want it to be like this: ‌

{{message('#000')}}
Dharman
  • 30,962
  • 25
  • 85
  • 135
AlirezaAhmadi
  • 72
  • 1
  • 11
  • 1
    Does this answer your question? [Displaying HTML with Blade shows the HTML code](https://stackoverflow.com/questions/29253979/displaying-html-with-blade-shows-the-html-code) – Peppermintology Apr 18 '22 at 05:58

1 Answers1

0

You can define the method in model, if you have a message instance, you can get it like this:

{!! $message->customText('#000') !!}

Or if there is no message instance, you can define your method as static and get the result like this:

{!! Message::customText('#000') !!}
Rouhollah Mazarei
  • 3,969
  • 1
  • 14
  • 20