'How can I display an html text as a function in the blade?
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')}}
Solution 1:[1]
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') !!}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rouhollah Mazarei |
