If you want to create a controller with just one action, you can use __invoke() method and even create "invokable" controller.
Route:
Route::get('path/{id}', 'MyClass');
Artisan:
php artisan make:controller MyClass --invokable
Controller:
class MyClass extends Controller
{
public function __invoke($id)
{
return view('parent.child', [
'data' => MyModel::findOrFail($id)
]);
}
}
Top comments (0)