I have been off from programming for a about a year. I had a project made in Laravel 7 and now when updated to Laravel 8, I have found a lot of differences.
But one thing that I can’t seem to fix is routing for get/post on same view.
For example:
Route::get('/edit-coupon/{coupon_id}', [App\Http\Controllers\CouponController::class, 'edit_coupon'])->name('edit-coupon');
Route::post('/edit-coupon', ['as' => 'edit-coupon','uses'=> [App\Http\Controllers\CouponController::class, 'update_coupon']])
Is there some way to change this routing without changing anything else?
As this was a big project of mine that I worked on for 2 years and it’s to complicated to change all structure. Example above is only 1 from like 50 pieces, that uses this type of structure.
Error:
TypeError
ReflectionFunction::__construct(): Argument #1 ($function) must be of type Closure|string, array given
http://127.0.0.1/edit-coupon
>Solution :
The routing updates from 7 to 8 were optional (https://laravel.com/docs/8.x/upgrade#routing) i.e. it’s only on new projects that the old routing wouldn’t work out of the box.
Your specific error comes from the 'uses' => [...]
part of the route.
If you’re wanting to move over to the new style i.e. using the ::class
syntax then you’ll need to remove (or comment out) the $namespace
property in the RouteServiceProvider
.