Routing and Controllers
When to Activate This Skill
Activate this skill whenever:
- Creating new controllers or modifying existing ones
- Registering routes in
routes/web.phpor other route files - Working with RESTful resource routing
- Understanding how routes map to Wayfinder TypeScript actions
- Troubleshooting missing controller actions or route registration issues
The Complete Workflow
When creating a new controller with a route:
Create the controller using Artisan:
php artisan make:controller JobController --no-interactionImplement the controller action with proper type hints and return types:
final class JobController { public function show(int $id): string { return "Job details for job {$id}"; } }Register the route in
routes/web.php:use App\Http\Controllers\JobController; Route::middleware(['auth', 'verified'])->group(function () { Route::resource('jobs', JobController::class) ->only(['show']); });Generate Wayfinder TypeScript actions:
php artisan wayfinder:generate --no-interactionUse the generated action in React components:
import JobController from '@/actions/App/Http/Controllers/JobController'; <Link href={JobController.show(jobId).url}>View Job</Link>
RESTful Resource Routing
This project uses Laravel's resource routing convention:
Route::resource('jobs', JobController::class)
->only(['index', 'show', 'create', 'store', 'edit', 'update', 'destroy']);
Common patterns:
.only(['index', 'show'])— Read-only resources.only(['show'])— Single action (like job details).only(['store', 'update', 'destroy'])— Mutation actions
Critical: Routes Must Be Registered for Wayfinder
Wayfinder only generates TypeScript action files for routes that are actually registered in your route files.
If you create a controller but don't register its route, Wayfinder won't generate the TypeScript action file, and you'll get import errors in your React components.
Troubleshooting Missing Action Files
If import JobController from '@/actions/...' fails:
- Check that the route is registered in
routes/web.php - Verify the controller class name matches the import path
- Run
php artisan wayfinder:generate --no-interactionagain - Check that the generated file exists in
resources/js/actions/
If still missing, activate the troubleshooting skill for further diagnosis.