【发布时间】:2019-06-04 20:48:54
【问题描述】:
我在Routes 文件夹中的api.php 如下所示:
<?php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::post('login', 'Api\User\LoginController@login');
和web.php如下:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/system/login', 'System\LoginController@index');
这是System\LoginController.php 的index 方法上的代码:
class LoginController extends Controller
{
use Requestable;
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$response = $this->post('api/login',$request->all());
$responseArray = json_decode($response->getBody(), true);
session()->put('access_token',$responseArray['data']['token']);
return redirect()->to('/system/dashboard');
//
}
所以基本上,我在同一个项目中使用 api。项目文件夹在 xampp 的 htdocs 内。所以每当我打开并使用 Apache 服务器时,api 发送数据就好了。但是,如果我使用 @ 987654332@为项目服务的命令,每次我尝试从api获取数据时,服务器都不会抛出任何错误,而是挂断,即使经过很长时间也不返回数据。我想这是服务器如何处理工匠服务的问题。请有人帮我解决这个问题?
【问题讨论】:
-
htdocsofxampp,请使用 xampp 内置 Web 服务器 (apache) 而不是使用php artisan serve。问题可能在于 serve 命令仅生成一个 php 进程实例来处理请求这一事实。因此,它卡住了,因为它在等待自己。请参阅this discussion 了解更多信息。
标签: php laravel laravel-5 laravel-artisan