У меня есть система, в которой перечислены спортивные игроки, и я использую привязку модели в Laravel 5.2 для извлечения модели игрока на основе фрагмента в URL. В некоторых случаях написание имени игрока могло измениться, поэтому у меня есть промежуточная таблица, где я ищу старый слаг и, если он найден, замените его новым слагом в URL и перенаправьте на новый URL. Локально это работает нормально, и на моем живом сервере это также работает, но на живом сервере регистрируется исключение, которое, по-видимому, указывает на то, что метод контроллера маршрута запускается даже при перенаправлении.
Маршрут:
Route::get('{playerSlug}', ['as' => 'player.main', 'uses' => 'PlayersController@player']);
Переплет:
Route::bind('playerSlug', function($value)
{
$player = Player::getPlayerBySlug($value);
if ( ! $player)
{
return App::abort(404);
}
elseif(is_string($player))
{
return \Redirect::to(URL::to($player), 301)->send();
}
else
{
return $player;
}
});
Запуск метода контроллера:
public function player($wordPlayers, $player, $scope = null)
{
$season = $player->latestSeason();
Исключение:
[2016-02-19 00:34:56] production.ERROR: BadMethodCallException: Method [latestSeason] does not exist on Redirect. in /home/forge/cuetracker.net/vendor/laravel/framework/src/Illuminate/Http/RedirectResponse.php:198
Stack trace:
#0 /home/forge/cuetracker.net/app/Http/Controllers/PlayersController.php(72): Illuminate\Http\RedirectResponse->__call('latestSeason', Array)
#1 [internal function]: App\Http\Controllers\PlayersController->player('Players', Object(Illuminate\Http\RedirectResponse))
#2 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9137): call_user_func_array(Array, Array)
#3 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9199): Illuminate\Routing\Controller->callAction('player', Array)
#4 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9179): Illuminate\Routing\ControllerDispatcher->call(Object(App\Http\Controllers\PlayersController), Object(Illuminate\Routing\Route), 'player')
#5 [internal function]: Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#6 /home/forge/cuetracker.net/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#7 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#8 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9656): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#9 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9180): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#10 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9167): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(App\Http\Controllers\PlayersController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'player')
#11 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(8262): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'App\\Http\\Contro...', 'player')
#12 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(8249): Illuminate\Routing\Route->runController(Object(Illuminate\Http\Request))
#13 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(7977): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#14 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#15 /home/forge/cuetracker.net/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#16 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#17 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9656): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#18 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(7978): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#19 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(7969): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#20 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(7959): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#21 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(2381): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#22 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#23 /home/forge/cuetracker.net/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#24 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(13111): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#25 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#26 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9666): call_user_func_array(Array, Array)
#27 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#28 /home/forge/cuetracker.net/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#29 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(11675): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#30 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#31 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9666): call_user_func_array(Array, Array)
#32 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#33 /home/forge/cuetracker.net/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#34 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(12850): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#35 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#36 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9666): call_user_func_array(Array, Array)
#37 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#38 /home/forge/cuetracker.net/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#39 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(12787): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#40 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#41 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9666): call_user_func_array(Array, Array)
#42 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#43 /home/forge/cuetracker.net/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#44 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(3183): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#45 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#46 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9666): call_user_func_array(Array, Array)
#47 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#48 /home/forge/cuetracker.net/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#49 /home/forge/cuetracker.net/app/Http/Middleware/EnableQueryLog.php(18): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#50 [internal function]: App\Http\Middleware\EnableQueryLog->handle(Object(Illuminate\Http\Request), Object(Closure))
#51 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9666): call_user_func_array(Array, Array)
#52 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#53 /home/forge/cuetracker.net/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#54 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#55 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(9656): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#56 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(2328): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#57 /home/forge/cuetracker.net/bootstrap/cache/compiled.php(2312): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#58 /home/forge/cuetracker.net/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#59 {main}
Надеюсь, кто-нибудь может мне помочь, пожалуйста, дайте мне знать, если вам нужно больше информации!
Предполагаемое поведение, я полагаю.
Привязка модели позволяет настроить способ возврата данных из модели для этот параметр маршрута (в твоем случае {playerSlug}
), но вы в любом случае заканчиваете методом контроллера или замыканием.
Других решений пока нет …