Let's say I want to make a RESTful API for external devices such as Android, and at the same time I want to consume this API using web routes and Blade templates.
Route: api/articles/{id}/edit
public function API_edit(Article $article)
{
$article->body = request('body');
$article->save();
return response()->json([...]);
}
Now here's the thing. What should I do in order to not repeat myself? Because I guess it's not OK to create another method that basically does the same as API_edit.
Route: articles/{id}/edit
public function edit(Article $article)
{
$article->body = request('body');
$article->save();
return redirect()->back()->with(['message' => 'Article edited']);
}
This must be wrong, it's a simple example but what if the logic is more complex? It doesn't feel right.