在Laravel 5.1上,方法未收回發佈數據。
這是我的方法,其中$ request不存儲通過發佈發送的數據。
class ProjectCommentController extends Controller
{
public function store(Request $request,$projectId)
{
$this->validate($request, [
'description' => ['required'],
'status' => ['required'],
'profile_id' => ['required']
]);
$project = Project::findOrFail($projectId);
return $project->comments()->save(new Comment([
'description' => $request->input('description'),
'status' => $request->input('status'),
'profile_id' => $request->input('profile_id')
]));
}
}
這是我如何把它從我的測試:
public function testProjectCommentCreation()
{
$category = factory(\App\Category::class)->create();
$project = factory(\App\Project::class)->create([
"category_id" => $category->id
]);
$profile = factory(\App\Profile::class)->create();
$comment = factory(\App\Comment::class)->make([
"profile_id"=>$profile->id
]);
$this->post(route('api.projects.comments.store', ['projects' => $project->id]), $comment->jsonSerialize(), $this->jsonHeaders)
->seeInDatabase('comments', ['project_id'=>$project->id,'description'=>$comment->description])
->assertResponseOk();
}
這是$ comment-> jsonSerialize()存儲:
array(3) {
'description' =>
string(10) "zFG8bW7EIz"
'status' =>
string(6) "active"
'profile_id' =>
int(629)
}
這是我的路線:
Route::resource('projects.comments','ProjectCommentController',['only'=>['index','store']]);
我的方法接收$ projectId從URL和那是工作,但請求變空,沒有我發送的數據$ comment-> jsonSerialize()
輸出[],但由於某種原因,我刪除頭Content-type應用程序/ JSON它的工作 –