show()の引数で文字列を使う
Controllerのshowのidに数字が来たら普通にfind、文字列が来たらwhereにする。
public function show($id) { if (is_numeric($id)) { $tag = Tag::find($id); } else { $tag = Tag::where('name', '=', $id)->first(); } }
Controllerのshowのidに数字が来たら普通にfind、文字列が来たらwhereにする。
public function show($id) { if (is_numeric($id)) { $tag = Tag::find($id); } else { $tag = Tag::where('name', '=', $id)->first(); } }