Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

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:


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('', ['post' => $post ]);


Add new comment

Restricted HTML


Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.


Contact Us

All the content is FREE but I still need your help


Become a patreon