find
Route::get('/product/{id?}', function($id=null) {
// find는 id 쓸 때 씀
// 코드 해석: 기본 id는 null로 저장하고, 만약 input parmeter에 id이 null 아닌 다른 데이터가 있다면, 특정 id를 가진 데이터만 리턴, 없으면 해당 테이블 다 리턴
return $id ? Product::find($id) : Product::all();
where
Route::get('/product/{name?}', function($name=null) {
// where은 parameter 다 됨
// 코드 해석: 기본 name는 null로 저장하고, 만약 input parmeter에 name이 null 아닌 다른 데이터가 있다면, 특정 name를 가진 데이터만 리턴, 없으면 해당 테이블 다 리턴
return $name ?Product::where('name', $name)->get() : Product::all();
pluck
Route::get('/product/{name?}', function($name=null) {
// pluck은 말 그대로 딱 특정 column 데이터만 뽑을 때 사용, get과 다른 이유는 json 형태의 데이터를 반환하는게 아니라 list 형태로 데이터를 보냄
// 코드 해석: 기본 name는 null로 저장하고, 만약 input parmeter에 name이 null 아닌 다른 데이터가 있다면, 특정 name를 가진 column 데이터만 리턴, 없으면 해당 테이블 다 리턴
return $name ?Product::where('name', $name)->pluck('name') : Product::all();