php - Laravel 4 applying custom filters to routes - error undefined offset -


trying prevent non-admin users accessing pages. must not doing correctly though because i'm getting error of undefined offset: 1 while trying access admin page while logged in admin.

filter

route::filter('admin', function() { if (!auth::user() || auth::user()->permissions != 1) return redirect::to('/'); }); 

routes

route::resource('deals', 'dealscontroller');  route::resource('blog', 'postscontroller');  route::group(array('before' => 'admin'), function() {     route::get('deals/create', 'dealscontroller');     route::get('blog/create', 'postscontroller'); }); 

i can't put filter on constructor of deals or blog controller because index page each of routes needs accessible users. when i'm not logged admin, routes function correctly , redirect home page when trying visit page admin-only. insights.

just solved problem, occurring because of routing. trying apply route group filter routes had been defined resource. when removed group routes , did research on using beforefilters in constructor, found can exclude function, solving problem.

this line of code solution

$this->beforefilter('admin', array('except' => 'index')); 

i hadn't know use except property, works well.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -