我刚刚继承了一个laravel应用程序,需要将它从4迁移到5.除了filters.php文件之外,在遵循指南后一切都很好。
指南说要将它们转移到RouteServiceProvider
的引导方法,并在使用middleware
过滤之前替换,但它只是不起作用。我是laravel的新手,不知道一切如何运作。
这是我尝试迁移的过滤器之一:
Route::filter('campaign.edit', function($route)
{
$campaign_id = $route->getParameter('id');
if (is_null(Namespace\Campaign::find($campaign_id))) {
if (Input::get('campaign_id')) {
$campaign_id = Input::get('campaign_id');
} else if (Input::get('track_id')) {
$track_id = Input::get('track_id');
$track = Namespace\Track::find($track_id);
$campaign_id = $track->campaign_id;
} else {
return;
}
}
if (false === Auth::user()->canEditCampaign($campaign_id)) {
return App::abort(403);
}
});
我怎样才能迁移这件作品?
答案 0 :(得分:0)
通过使用该功能并从中创建中间件来找到解决方案,例如下面的那个。
namespace App\Http\Middleware;
use Closure;
use NameSpace;
use Input;
use Illuminate\Support\Facades\Auth;
class CampaignEdit
{
public function handle($request, Closure $next)
{
$campaign_id = $request->route('id');
if (is_null(NameSpace\Campaign::find($campaign_id))) {
if (Input::get('campaign_id')) {
$campaign_id = Input::get('campaign_id');
} else if (Input::get('track_id')) {
$track_id = Input::get('track_id');
$track = NameSpace\Track::find($track_id);
$campaign_id = $track->campaign_id;
} else {
return;
}
}
if (false === Auth::user()->canEditCampaign($campaign_id)) {
return App::abort(403);
}
return $next($request);
}
}