Basic Controllers: Single Action Controllers

Single Action Controllers

<?php namespace App\Http\Controllers; use App\User; use App\Http\Controllers\Controller; class ShowProfile extends Controller
{ /**
     * Show the profile for the given user.
     *
     * @param  int  $id
     * @return Response
     */ public function __invoke($id)
    { return view('user.profile', ['user' => User::findOrFail($id)]); } }
Route::get('user/{id}', 'ShowProfile');
Php artisan make:controller ShowProfile --invokable

When registering routes for single action controllers, you do not need to specify a method.

Related concepts

Basic Controllers: Single Action Controllers — Structure map

Clickable & Draggable!

Basic Controllers: Single Action Controllers — Related pages: