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

yanikkumar's avatar

Need Suggestion What to use (API or WEB) next in Laravel Project?

I am working on the project All CRUD operations are made but I want to continue project with more features and build some more modules. Should I create API routes now to continue project so that I can use jquery for one click operations. For eg: To like post I don't want to reload the whole page. Just request the ajax call to the route and do the action. Similar thing with follow system. What should I use he api routes and jquery ajax calls. Or should I use live wire to continue the project or vue js for upcoming featuers etc. I'm confused right now to continue with features.

0 likes
2 replies
trin's avatar

no best practice for your question, only your choice. im always use only api. my laravel not generate html. all front-end generated by reACt, vue, angular etc. payment for it -- i use only 50% power of laravel. in yout case i recommended use both, api and web. for like use api, for content livewire

martinbean's avatar

@yanikkumar Only build an API if you actually need an API.

If all you’re wanting to do is a small number of things over AJAX, then you can return JSON responses if the request was made via AJAX:

class PostLikeController extends Controller
{
    public function store(Request $request, Post $post)
    {
        $request->user()->like($post);

        if ($request->expectsJson()) {
            return response()->json(null, 204);
        }

        return redirect()
            ->route('post.show', compact('post'))
            ->with('success', __('Post was liked.'));
    }
}

Please or to participate in this conversation.