Home > Mobile >  App\Http\Controllers\PostController` is not invokable:
App\Http\Controllers\PostController` is not invokable:

Time:09-14

UnexpectedValueException

Invalid route action: [App\Http\Controllers\PostController].

at C:\Users\DELL\Desktop\xampp\htdocs\Anka\vendor\laravel\framework\src\Illuminate\Routing\RouteAction.php:92 88▕ */ 89▕ protected static function makeInvokable($action) 90▕ { 91▕ if (! method_exists($action, '__invoke')) { ➜ 92▕ throw new UnexpectedValueException("Invalid route action: [{$action}]."); 93▕ } 94▕ 95▕ return $action.'@__invoke'; 96▕ }

i App\Http\Controllers\PostController is not invokable: The controller class App\Http\Controllers\PostController is not invokable. Did you forget to add the __invoke method or is the controller's meth od missing in your routes file?

1
C:\Users\DELL\Desktop\xampp\htdocs\Anka\vendor\laravel\framework\src\Illuminate\Routing\RouteAction.php:47 Illuminate\Routing\RouteAction::makeInvokable()

2
C:\Users\DELL\Desktop\xampp\htdocs\Anka\vendor\laravel\framework\src\Illuminate\Routing\Route.php:190 Illuminate\Routing\RouteAction::parse()

PostController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PostController extends Controller
{
    public function index()
    {
        return view('posts/index');
    }
}

Posts endpoints

Route::get('/posts', PostController::class, 'index');

CodePudding user response:

Try this

PostController
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PostController extends Controller
{
    public function index()
    {
        return view('posts/index');
    }
}



//posts endpoints
use App\Http\Controllers\PostController;

Route::get('/posts', [PostController::class, 'index']);
  • Related