0

I've build a Laravel Rest API with Dingo\API following a tutorial. I've set this up as virtual host at http://site.test

Vhosts are set up in httpd.conf and /etc/hosts files.

But, when I go to http://site.test, it shows the full project directory. So I have to click into the /routes/api.php, but I get the following error:-

Uncaught Error: Call to undefined function app() in /Users/param/Desktop/api/routes/api.php undefined function app() in /Users/param/Desktop/api/routes/api.php

I ran this during set up:

php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"

My composer.json file

"require": {
    "php": ">=7.1.3",
    "dingo/api": "^2.1",
    "fideloper/proxy": "^4.0",
    "laravel/framework": "5.8.*",
    "laravel/tinker": "^1.0"
}

RouteServiceProvider.php file

protected function mapApiRoutes()
{
    Route::prefix('api')
         ->middleware('api')
         ->namespace($this->namespace)
         ->group(base_path('routes/api.php'));
}

routes/api.php file

$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function ($api) {
    $api->get('/',  function () {
        return ['fruits'=> 'Delicious'];
    });
});

.env file

API_PREFIX=api
API_DEBUG=true

Would love any help in the right direction -- I can't figure out why http://site.test/api return that error?

Lakhwinder Singh
  • 5,536
  • 5
  • 27
  • 52
partap
  • 35
  • 6

1 Answers1

0

For anybody looking for a solution to this assuming your Virtual host is http://site.test On your.env file put http://site.test as your API_URL environment variable and put site.test as your API_DOMAIN environment variable

user2293554
  • 379
  • 1
  • 7
  • 15