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

davy_yg's avatar
Level 27

Laravel API

Hello,

This is Laravel API. I never used Laravel API before, I have tried using CI API.

BannerController.php

public function listBanner() {
        $today = date("Y-m-d");
        $banner = BannerModel::where('status', '1')
                            ->where('expire_date', '>', $today)
                            ->get();


        return response()->json(array(
            'status' => 200,
            'message'=> 'Banner listed',
            'data'=> $banner,
            'path_banner' => asset('/banners') 
        ), 200);
    }

I wonder how do you call the API since it is in Json format. Any idea? I also wonder why the API is not in it's own server. This one is united with the front end.

Thanks in advance.

0 likes
3 replies
Vilfago's avatar

You return a json, so you can call it with Ajax, for example

davy_yg's avatar
Level 27

Is there any other way to translate json with laravel syntax so that you can show it in the laravel frontend?

Please or to participate in this conversation.