Route::apiResource nedir?
Route::apiResource('users','UserController');
Aşağıdaki 5 metodun yerine Route::apiResource kullanılabilir.
Route::get('users','UserController@index');
public function index(){
return User::all();
}
Route::get('users/{id}','UserController@show');
public function show($id){
...
return response($user, Response::HTTP_CREATED)
}
Route::post('users','UserController@store');
public function store(Request $request){
...
return response($user, Response::HTTP_CREATED)
}
Route::put('users/{id}','UserController@update');
public function update(Request $request){
...
return response($user, Response::HTTP_ACCEPTED)
}
Route::delete('users/{id}','UserController@destroy');
public function destroy(Request $request){
...
return response($user, Response::HTTP_NO_CONTENT)
}
Comments
Post a Comment