升级到 laravel 5.0
Upgrade to laravel 5.0
我升级到 Laravel 5.0,70% 的应用程序都在运行,但我在登录时遇到问题。我有宏 -> html::macro 和 response::macro。 html::macro 正在工作 - 我使用 html::macros 进行导航。但是如果我需要 response::macro,我会得到这个错误:
exception 'BadMethodCallException' with message 'Method ajaxRedirect does not exist.'
这是我的电话:
public function postAuthenticate()
{
try
{
$this->service->authenticate(Input::except(['_token', 'extended']));
}
catch(AuthenticationNotValidException $ex)
{
throw new AuthenticationNotValidAjaxException($ex->getMessage());
}
if (Session::has('tempRequest'))
{
$this->service->addTemporaryRequest(Auth::user());
}
return Response::ajaxRedirect(route(
(Auth::user()->isAdmin()) ? 'admin.dashboard' : 'customer.dashboard'));
}
这里是宏:
Response::macro('ajaxRedirect', function($url)
{
return Response::json(array(
'state' => true,
'redirect' => $url
));
});
为什么我会收到这个错误,我是不是错过了什么? Laravel 4 一切正常。如有任何提示,我们将不胜感激。
参考文献:
这是做出 custom/macro laravel-5 响应的方法
创建您的服务提供商
<?php namespace App\Providers;
use Response;
use Illuminate\Support\ServiceProvider;
class ResponseMacroServiceProvider extends ServiceProvider {
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
Response::macro('ajaxRedirect', function($url)
{
return Response::json(array(
'state' => true,
'redirect' => $url
));
});
}
}
并在app/Providers
中保存为ResponseMacroServiceProvider.php
。
相应地更新提供商列表
<?php
return [
...
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
|--------------------------------------------------------------------------
|
| The service providers listed here will be automatically loaded on the
| request to your application. Feel free to add your own services to
| this array to grant expanded functionality to your applications.
|
*/
'providers' => [
...
'App\Providers\ResponseMacroServiceProvider',
],
...
在 config/app.php
.
享受
您应该可以在您的控制器中使用它
return Response::ajaxRedirect(route(
(Auth::user()->isAdmin()) ? 'admin.dashboard' : 'customer.dashboard'));
根据需要。
我升级到 Laravel 5.0,70% 的应用程序都在运行,但我在登录时遇到问题。我有宏 -> html::macro 和 response::macro。 html::macro 正在工作 - 我使用 html::macros 进行导航。但是如果我需要 response::macro,我会得到这个错误:
exception 'BadMethodCallException' with message 'Method ajaxRedirect does not exist.'
这是我的电话:
public function postAuthenticate()
{
try
{
$this->service->authenticate(Input::except(['_token', 'extended']));
}
catch(AuthenticationNotValidException $ex)
{
throw new AuthenticationNotValidAjaxException($ex->getMessage());
}
if (Session::has('tempRequest'))
{
$this->service->addTemporaryRequest(Auth::user());
}
return Response::ajaxRedirect(route(
(Auth::user()->isAdmin()) ? 'admin.dashboard' : 'customer.dashboard'));
}
这里是宏:
Response::macro('ajaxRedirect', function($url)
{
return Response::json(array(
'state' => true,
'redirect' => $url
));
});
为什么我会收到这个错误,我是不是错过了什么? Laravel 4 一切正常。如有任何提示,我们将不胜感激。
参考文献:
这是做出 custom/macro laravel-5 响应的方法
创建您的服务提供商
<?php namespace App\Providers;
use Response;
use Illuminate\Support\ServiceProvider;
class ResponseMacroServiceProvider extends ServiceProvider {
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
Response::macro('ajaxRedirect', function($url)
{
return Response::json(array(
'state' => true,
'redirect' => $url
));
});
}
}
并在app/Providers
中保存为ResponseMacroServiceProvider.php
。
相应地更新提供商列表
<?php
return [
...
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
|--------------------------------------------------------------------------
|
| The service providers listed here will be automatically loaded on the
| request to your application. Feel free to add your own services to
| this array to grant expanded functionality to your applications.
|
*/
'providers' => [
...
'App\Providers\ResponseMacroServiceProvider',
],
...
在 config/app.php
.
享受
您应该可以在您的控制器中使用它
return Response::ajaxRedirect(route(
(Auth::user()->isAdmin()) ? 'admin.dashboard' : 'customer.dashboard'));
根据需要。