It's the same as, so I don't know what the hell it's good for.
$foo = 'foo';
$page = 'page';
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi guys! I've been using the following code to send variables from my web routes to my controller functions for years. It works, but the code is pretty ugly. routes/web.php:
Route::get( 'about-us', [ 'uses' => 'MyController@about_us', 'foo' => 'bar', 'page' => 'about' ] )->name( 'about-us' );
Receive the values in my controller, app/Http/Controllers/MyController.php:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class MyController extends Controller
{
public function about_us( Request $request ) {
$foo = $request->route()->getAction()[ 'foo' ];
$page = $request->route()->getAction()[ 'page' ];
return view( 'about-us' );
}
}
Is there a cleaner, newer ways to do this? Thank you for any help.
Please or to participate in this conversation.