Route not found with Octane

199 Views Asked by At

I'm very new to this and can't understand what's happening. Tried multiple answers from other threads.

Trying to build a search form using Laravel and Octane. There is a problem with the action method on the form

<form role="form" id="form-buscar" action="{{ route('search') }}" method="POST">
     <textarea class="form-control" type="textarea" name="search" placeholder="Search..." required></textarea>
     <button class="btn btn-success pull-right" type="submit">Search</button>
</form>

And routes

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Laravel\Octane\Facades\Octane;
use Illuminate\Http\Response;

Route::get('/', [SearchController::class,'index']);

Octane::route('GET', '/search', function($request) {
    return Route::toResponse($request, view('search'));
});

The form is on the index page and when I tried to load it, I got the error

Route [/search] not defined.

pointing on action="{{ route('search') }}"

2

There are 2 best solutions below

0
congld2509 On

If you using php artisan route:cache the route which defined by Octane:route will be not found.

You can read this in detail at: https://github.com/laravel/octane/issues/596

0
Switi On

you can this route add on your web.php Route::get('/search', [SearchController::class, 'index'])->name('search');

Search

By using route('search'), Laravel will generate the correct URL for the '/search' route, and you won't encounter the "Route [/search] not defined" error.

Make sure that your Controller index method is properly implemented your logic.