URL to do request on Laravel

2019-06-10 06:48发布

This may be a silly question, but I haven't find any way to solve it yet. My project mate wrote server side of our project using Laravel. My job is to develop Android App. I know how to send and receive JSON between Android and PHP. However, I don't know much about Laravel. So I don't know which URL should I use to send/receive JSON.

To which URL should I send my JSON to use the following post_list() method under the file my_application_name/application/controllers/menucategory.php ?

<?php

class MenuCategory_Controller extends Base_Controller {

    public $restful = true;

    public function post_list() {
        $categories = MenuCategory::all();
        $cat = null;
        foreach ($categories as $category) {
            $cat[] = array(
                'id' => $category->id,
                'name' => $category->name
            );
        }
        return Response::json(array('categories' => $cat));
    }
}

?>

1条回答
闹够了就滚
2楼-- · 2019-06-10 07:34

Since the controller is restful, you just need to point to the name of the controller, and the name of the method (without the action)

e.g., in this case, you post to menucategory/list since it's the MenuCategory controller, and you post to list

More information on this can be seen in the laravel docs here: http://laravel.com/docs/controllers#restful-controllers

查看更多
登录 后发表回答