क्या फ़िल्टर के भीतर रूट पैरामीटर तक पहुंच बनाना संभव है?फ़िल्टर के लिए तर्क पास करना - लार्वेल 4
उदा।
Route::group(array('prefix' => 'agency'), function()
{
# Agency Dashboard
Route::get('{agencyId}', array('as' => 'agency', 'uses' => 'Controllers\Agency\[email protected]'));
});
मैं अपने फिल्टर के भीतर इस $ agencyId पैरामीटर का उपयोग करना चाहते हैं:: मैं $ agencyId पैरामीटर उपयोग करना चाहते
Route::filter('agency-auth', function()
{
// Check if the user is logged in
if (! Sentry::check())
{
// Store the current uri in the session
Session::put('loginRedirect', Request::url());
// Redirect to the login page
return Redirect::route('signin');
}
// this clearly does not work..? how do i do this?
$agencyId = Input::get('agencyId');
$agency = Sentry::getGroupProvider()->findById($agencyId);
// Check if the user has access to the admin page
if (! Sentry::getUser()->inGroup($agency))
{
// Show the insufficient permissions page
return App::abort(403);
}
});
बस संदर्भ के लिए मैं इस तरह के रूप में अपने नियंत्रक में इस फिल्टर फोन:
class AgencyController extends AuthorizedController {
/**
* Initializer.
*
* @return void
*/
public function __construct()
{
// Apply the admin auth filter
$this->beforeFilter('agency-auth');
}
...
आप इस '$ का उपयोग कर सकते हैं:
एक अन्य विकल्प
Route
मुखौटा है, जो उपयोगी है जब आप एक मार्ग के बाहर हैं के माध्यम से पैरामीटर को पुनः प्राप्त करने के लिए है एजेंसीआईडी = अनुरोध :: सेगमेंट (2) 'फ़िल्टर में 'एजेंसी आईडी' प्राप्त करने के लिए –