sustained
10 months ago

Very strange behaviour when using ::class in routes file.

Posted 10 months ago by sustained

This doesn't make any sense?

use App\Http\Controllers\ReplyController;

Route::resource('threads', ThreadController::class);
Route::post('/threads/{thread}/replies', [ReplyController::class, 'store']);

// ^ All routes work.
Route::resource('threads', ThreadController::class);
Route::post('/threads/{thread}/replies', [ReplyController::class, 'store']);

// ^ Only the routes on the threads resource work, otherwise:
// ReflectionException, Function () does not exist
use App\Http\Controllers\ThreadController;
use App\Http\Controllers\ReplyController;

Route::resource('threads', ThreadController::class);
Route::post('/threads/{thread}/replies', [ReplyController::class, 'store']);

// ^ Only the store reply route works, otherwise:
// App\Http\Controllers\App\Http\Controllers\ThreadController does not exist
use App\Http\Controllers\ThreadController;

Route::resource('threads', ThreadController::class);
Route::post('/threads/{thread}/replies', [ReplyController::class, 'store']);

// ^ None of the routes work:
// App\Http\Controllers\App\Http\Controllers\ThreadController does not exist

I would expect either #2 or #3 to be the one where all routes work???

Please sign in or create an account to participate in this conversation.