[英]Laravel localhost api server error (truncated...)
i'm new to this api thing, i get the basic idea, so i followed this tutorial: https://appdividend.com/2018/04/17/laravel-guzzle-http-client-example/我是这个 api 的新手,我明白了基本的想法,所以我遵循了这个教程: https://appdividend.com/2018/04/17/laravel-guzzle-http-client-example/
but everytime i tried rolling, it gives me this error但每次我尝试滚动时,它都会给我这个错误
api caller controller: api 呼叫者 controller:
class DataController extends Controller
{
public function postRequest()
{
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'http://localhost:8001/api/store', [
'form_params' => [
'name' => 'krunal',
]
]);
$response = $response->getBody()->getContents();
echo '<pre>';
print_r($response);
}
public function getRequest()
{
$client = new \GuzzleHttp\Client();
$request = $client->get('http://localhost:8001/api/index');
$response = $request->getBody()->getContents();
echo '<pre>';
print_r($response);
exit;
}
}
api caller route: api 来电路线:
Route::get('/', function () {
return view('welcome');
});
Route::get('post','DataController@postRequest');
Route::get('get','DataController@getRequest');
api provider controller: api 提供商 controller:
class GuzzlePostController extends Controller
{
public function store(Request $request)
{
$data = new GuzzlePost();
$data->name=$request->get('name');
$data->save();
return response()->json('Successfully added');
}
public function index()
{
$data = GuzzlePost::all();
return response()->json($data);
}
}
api provider route: api 供应商路线:
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::post('store', 'GuzzlePostController@store');
Route::get('index', 'GuzzlePostController@index');
the api caller served on port 8000, the provider served on port 8001 api 呼叫者在端口 8000 上服务,提供者在端口 8001 上服务
thanks in advance提前致谢
I think that you forgot run migrations and there no guzzle_posts table exists.我认为您忘记了运行迁移并且不存在 guzzle_posts 表。 Check it out
看看这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.