What is the region() function returning?
How to add prefix to URL in Pest Laravel
I want to add a dynamic prefix to the pest test as we do in Laravel like this
Route::prefix(region())
->resource('regions', RegionController::class)
->except('show')
->whereNumber('region');
Now similarly I want to add prefix to my test so that I can test the above route code.
Here is something I want to achieve. I now that in withPrefix method doesn't exist. Is their any similar method for that?
test('index page is loading', function () {
userLogin();
$response = $this->withPrefix(region())->get(route('regions.index'));
$response->assertStatus(200);
});
@murtaza1904 your route definition will not work like that... there is no Request (or URL) whenever your Routes get evaluated and cached (in production).
You really need a wildcard segment for the prefix (I use reg here since region will be taken by the ID segment):
Route::prefix({reg})
->resource('regions', RegionController::class)
->except('show')
->whereNumber('region');
Then your controller actions will receive a $reg parameter along with any Model-specific $region parameters to identify the model.
Please or to participate in this conversation.