我正在尝试从url获取多个参数并将它们发送到视图,但我得到的是未定义的变量。如何解决这个问题:
api.php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Session\Middleware\StartSession::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
'api' => [
'throttle:60,1',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];
}
frame.blade.php
Route::get('adwidth/{width}/adheight/{height}/aduser/{user_id}', function(){
return view('frame', compact('width','height','user_id'));
});
我正在使用laravel 5.3
答案 0 :(得分:0)
我找到了解决方案,我必须将这些参数传递给我的闭包,如下所示:
Route::get('adwidth/{width}/adheight/{height}/aduser/{user_id}', function($width, $height, $user_id){
return view('frame', compact('width','height','user_id'));
});