php - Route in dingo not work when make Api with dingo/api and laravel 5.1

476

I am making a test api with dingo and laravel 5.1 but i don't know why my code do not work as i expected. This is just a simple example but it's not work, please help me. This is my route code:

$api = app('Dingo\Api\Routing\Router');

Route::get('/', function () {
    return view('welcome');
});

//this function help use to manage functions on each version. this is version 0.1 (called version groups)
$api->version('v0.1', [ 'namespace'=>'App\Http\Controllers\Api'], function ($api) {
    $api->get('users/{id}', '[email protected]');
    $api->get('users/{id}', ['as' => 'users.index', 'users' => '[email protected]']);//make route
    app('Dingo\Api\Routing\UrlGenerator')->version('v0.1')->route('users.index');//finally, create new route
    //Route::get('/users/{id}', '[email protected]');
});

And this is my TestController code:

namespace app\Http\Controllers\Api;


use app\Http\Controllers\BaseController;

class TestController extends BaseController
{
    public function test($id){
        return $id;
    }
}

Very basic but it is not work when i try to get it from Postman, these code return a jason like this:

"message": "Function () does not exist",
"status_code": 500,

I am looking forward to your help, Thank you.

People are also looking for solutions to the problem: php - PDF cretaion of webpage with fpdf return blank

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.