私はlaravelが初めてで、単純なrest APIを実装しようとしています。
コントローラーを実装し、単体テストでテストしました。
私の問題は POST リクエストにあります。
テストを介して Input:json にはデータがあり、外部の REST クライアントを介して null を返します。
これは単体テストのコードです
$newMenu = array(
'name'=>'Christmas Menu',
'description'=>'Christmas Menu',
'img_url'=>'http://www.example.com',
'type_id'=>1,
);
Request::setMethod('POST');
Input::$json = $newMenu;
$response = Controller::call('menu@index');
私は何を間違っていますか?
アップデート:
これは本当に私を夢中にさせています
私は新しいlaravelプロジェクトをインスタンス化し、次のコードを持っています:
ルート
Route::get('test', 'home@index');
Route::post('test', 'home@index');
コントローラ:
class Home_Controller extends Base_Controller {
public $restful = true;
public function get_index()
{
return Response::json(['test'=>'hello world']);
}
public function post_index()
{
return Response::json(['test'=>Input::all()]);
}
}
CURL 呼び出し:
curl -H "Accept:application/json" -H"Content-type: application/json" -X POST -d '{"title":"world"}' http://localhost/laravel-post/public/test
応答:
{"test":[]}
誰かが間違っていることを指摘できますか。
これは私がlaravelを使用することを本当に妨げており、私はそのコンセプトが本当に好きでした.