0

I have this string:

<div class="my-card-container">
  <x-card :title="Hello Wordl"></x-card>
</div>

This string is coming from database, it lives in the Conent model's html property. I use it in my ContentController like this:

    public function serve(Request $request, string $uri = ''): View
    {
        $content = Content::whereUri($uri);

        return view('main', [
            'content' => $content->html,
        ]);
    }

In my main.blade.php:

@section('content')
<main>
    @include('main.content')
</main>
@stop

I want to render any available view components on my string.

Can I somehow enforce Laravel to apply the CardComponent or any other available component on that string?

1 Answer 1

1

The Blade::render() will help you.

Try this:

    public function serve(Request $request, string $uri = ''): View
    {
        $content = Content::whereUri($uri);

        $content = Blade::render($content);

        return view('main', [
            'content' => $content->html,
        ]);
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.