Home > Blockchain >  Cannot use positional argument after named argument error in web.php
Cannot use positional argument after named argument error in web.php

Time:06-03

Route::get(uri: 'scraper', ["App\Http\Controllers\ScraperController"::class, 'scraper'])->name(name:'scraper');

I wrote this line in web.php, then I got this error:

'Cannot use positional argument after named argument'

CodePudding user response:

You're attempting to define routes using named arguments when it's not necessary. You should write the following:

Route::get('scraper', [App\Http\Controllers\ScraperController::class, 'scraper'])->name('scraper');

You can read more about named arguments and how they differ from positional arguments.

CodePudding user response:

If you want to keep using named agruments, can do it as

Route::get(
    uri: 'scraper', 
    action: [App\Http\Controllers\ScraperController::class, 'scraper']
)
->name(name:'scraper');

Definition of Route::get() is like

/**
 *
 * @param string $uri
 * @param array|string|callable|null $action
 * @return \Illuminate\Routing\Route
 */
public static function get($uri, $action = null){}
  • Related