Home > Net >  Laravel 8 Routing Update?
Laravel 8 Routing Update?

Time:11-28

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

Routes file

    <?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::group(['middleware' => ['XSS']], function () {

  Route::get('/', [App\Http\Controllers\CommonController::class, 'view_index']);
  Route::get('/index', [App\Http\Controllers\CommonController::class, 'view_index'])->name('index');

  /* language */

  Route::get('/translate/{translate}',[App\Http\Controllers\CommonController::class, 'cookie_translate']);

  /* language */

  /* Profile */

  Auth::routes();

  Route::get('/logout', [App\Http\Controllers\Admin\CommonController::class, 'logout']);

  Route::get('/login/{provider}', 'Auth\LoginController@redirectToProvider');
  Route::get('/login/{provider}/callback', 'Auth\LoginController@handleProviderCallback');

  Route::get('/profile-settings', [App\Http\Controllers\ProfileController::class, 'view_profile_settings']);
  Route::post('/profile-settings', ['as' => 'profile-settings','uses'=> [App\Http\Controllers\ProfileController::class, 'update_profile']]);

  Route::get('/forgot', [App\Http\Controllers\CommonController::class, 'view_forgot']);
  Route::post('/forgot', ['as' => 'forgot','uses'=>[App\Http\Controllers\CommonController::class, 'update_forgot']]);
  Route::get('/reset/{user_token}', [App\Http\Controllers\CommonController::class, 'view_reset']);
  Route::post('/reset', ['as' => 'reset','uses'=>[App\Http\Controllers\CommonController::class, 'update_reset']]);

  /* Profile */

  /* pages */
  Route::get('/404', [App\Http\Controllers\CommonController::class, 'not_found']);
  Route::get('/page/{page_id}/{page_slug}', [App\Http\Controllers\PageController::class, 'view_page']);

  /* pages */

  /* shop */

  Route::get('/shop', [App\Http\Controllers\CommonController::class, 'view_all_items']);
  Route::get('/shop/{filter}', [App\Http\Controllers\CommonController::class, 'view_filter_items']);
  Route::get('/shop/{item_type}/{slug}', [App\Http\Controllers\CommonController::class, 'view_item_type']);
  Route::get('/shop/{type}/{id}/{slug}', [App\Http\Controllers\CommonController::class, 'view_category_items']);
  Route::post('/shop', ['as' => 'shop','uses'=> [App\Http\Controllers\CommonController::class, 'view_shop_items']]);
  Route::get('/shop-list', [App\Http\Controllers\CommonController::class, 'view_all_list_items']);

  /* shop */

  /* coupon */
  Route::get('/coupon', [App\Http\Controllers\CouponController::class, 'view_coupon']);
  Route::get('/add-coupon', [App\Http\Controllers\CouponController::class, 'add_coupon'])->name('add-coupon');
  Route::post('/add-coupon', [App\Http\Controllers\CouponController::class, 'save_coupon']);
  Route::get('/coupon/{coupon_id}',  [App\Http\Controllers\CouponController::class, 'delete_coupon']);
  Route::get('/edit-coupon/{coupon_id}',  [App\Http\Controllers\CouponController::class, 'edit_coupon'])->name('edit-coupon');
  Route::post('/edit-coupon', [App\Http\Controllers\CouponController::class, 'update_coupon']);
  /* coupon */

  /* cart */
  Route::get('/cart', [App\Http\Controllers\ItemController::class, 'show_cart']);
  Route::get('/cart/{ord_id}', [App\Http\Controllers\ItemController::class, 'remove_cart_item']);
  Route::post('/cart', ['as' => 'cart','uses'=> [App\Http\Controllers\ItemController::class, 'view_cart']]);
  Route::post('/coupon', ['as' => 'coupon','uses'=> [App\Http\Controllers\ItemController::class, 'view_coupon']]);
  Route::get('/cart/{remove}/{coupon}', [App\Http\Controllers\ItemController::class, 'remove_coupon']);
  /* cart */

  /* checkout */
  Route::get('/checkout', [App\Http\Controllers\ItemController::class, 'show_checkout']);
  Route::post('/checkout', ['as' => 'checkout','uses'=> [App\Http\Controllers\ItemController::class, 'view_checkout']]);
  Route::post('/2checkout', ['as' => '2checkout','uses'=> [App\Http\Controllers\ItemController::class, 'confirm_2checkout']]);
  Route::post('/paystack', ['as' => 'paystack','uses'=> [App\Http\Controllers\ItemController::class, 'redirectToGateway']]);
  Route::get('/paystack', [App\Http\Controllers\ItemController::class, 'handleGatewayCallback']);
  /* checkout */


  /* success */
  Route::get('/success/{ord_token}', [App\Http\Controllers\ItemController::class, 'paypal_success']);
  Route::get('/cancel', [App\Http\Controllers\ItemController::class, 'payment_cancel']);
  Route::get('/success', [App\Http\Controllers\ItemController::class, 'view_success']);
  /* success */


  /* purchases */

  Route::get('/purchases', [App\Http\Controllers\ItemController::class, 'view_purchases']);

  /* purchases */

  /* sitemap */
  Route::get('/sitemap.xml', [App\Http\Controllers\SitemapController::class, 'index']);
  Route::get('/sitemap.xml/items', [App\Http\Controllers\SitemapController::class, 'items']);
  Route::get('/sitemap.xml/category', [App\Http\Controllers\SitemapController::class, 'category']);
  Route::get('/sitemap.xml/subcategory', [App\Http\Controllers\SitemapController::class, 'subcategory']);
  Route::get('/sitemap.xml/pages', [App\Http\Controllers\SitemapController::class, 'pages']);
  Route::get('/sitemap.xml/users', [App\Http\Controllers\SitemapController::class, 'users']);
  /* sitemap */

});

CodePudding user response:

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.

  • Related