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?