Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SGUserFace's avatar

Create API

I'm creating an API The JSON is working properly The problem is I don't understand how to combine it with view

0 likes
6 replies
Sinnbeck's avatar

You need some kind of Javascript to load and parse the data

SGUserFace's avatar

I use axios. That's not the problem.

The problem is that the controller returns json and I probably need a view as well

Sinnbeck's avatar

What do you intend to do with the json? Render it as html? Do you use a framework like vue or react?

Ty's avatar

Why couldn't you do something like this?

$items = Items::all()->toJson();
return view('items.create', compact('items'));

Please or to participate in this conversation.