in this article, I'll show you how to create a controller with just one action, you can use __invoke() method and even create invokable controller.
to generate invokable controller you can use this command:
php artisan make:controller ShowProfile --invokable
Add route to this controller:
Route::get('post/{id}', 'ShowPost');
and in ShowPost.php file you can handle the incoming request in __invoke() method:
<?php
namespace App\Http\Controllers;
use App\Post;
use Illuminate\Http\Request;
class ShowPost extends Controller
{
/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function __invoke(Request $request, $id)
{
$post = Post::findOrFail($id);
return view('posts.show', ['post' => $post ]);
}
}