SpaceDogCS
SpaceDogCS

Reputation: 2968

Laravel website feeded by api

In normal laravel controller I return a view with the data

return view('folder.page', compact('data'))

But I'm building my website with an API to work also in mobile devices, how should I build my html with the API?

Update Important thing, the API is in the same project, it isn't an external api

Upvotes: 1

Views: 47

Answers (1)

user9896706
user9896706

Reputation:

I would suggest using a ViewComposer, in this way you can use the variables in your website. You can find more about ViewComposers at the following link:

https://laravel.com/docs/5.6/views#view-composers

You can then use the ViewComposer to do a request to your API and use that data. The data will then be assigned to your blade as a normal variable (such as {{$foo}})

Upvotes: 1

Related Questions