当我使用php artisan serve
运行应用程序时,每条路线都运行良好,但是当我尝试在nginx上运行时,所有路线都正常工作,/json.json
除外。它显示错误。
Constant LARAVEL_START already defined
这是routes.php
<?php
Route::get('/', function()
{
return View::make('hello');
});
Route::get('json.json', 'HomeController@temp');
Route::post('anotheroute', 'HomeController@p');
});
和HomeController.php
<?php
include 'index.php' ;
class HomeController extends BaseController {
public function showWelcome()
{
return View::make('hello');
}
public function temp()
{
header('Access-Control-Allow-Origin: *');
$x = select_artist_by_name();
return Response::json(array_keys($x));
}
答案 0 :(得分:3)
在我的情况下,我在laravel项目的外部文件中遇到此错误。
所以我检查了是否在包含文件之前定义了常量:
if (!defined('LARAVEL_START')) {
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
}