Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I do something very similar in my application, but after some trial and error myself I figured the best way to authenticate users and admins was to have two separate filters. So, here is what I do:</p> <p>I have an <code>auth</code> filter that simply logs a user in - </p> <pre><code>Route::filter('auth', function() { if (Auth::guest()) return Redirect::to('login'); }); </code></pre> <p>In addition to this, I have an <code>auth.admin</code> filter that checks for the logged in Users role:</p> <pre><code>Route::filter('auth.admin', function() { if(Auth::user()-&gt;userprofile-&gt;security_level &lt; 4) { return Redirect::route('projects.home'); } }); </code></pre> <p>One caveat to remember is that to not use the <code>auth.admin</code> filter, standalone, in your routes. Will throw an error when the user is not logged in. You can do something like:</p> <pre><code>Route::group(array('before' =&gt; 'auth'), function() { Route::get('user', array('as' =&gt; 'user.home', 'uses' =&gt; 'UsersController@index'));}); } Route::group(array('before' =&gt; 'auth|auth.admin'), function() { Route::get('user/create', array('as' =&gt; 'user.create', 'uses' =&gt; 'UsersController@create')); }); </code></pre> <p>With this setup, add the pages you want only your admin to access to the latter routing group with <code>auth</code> and <code>auth.admin</code>.</p> <p>Now, with this setup, you don't need to check for logic in your composer. Ideally, your routing (or your controller, based on what your argument is) should handle your routing logic.</p> <p>You can rewrite your composer like this:</p> <pre><code>View::composer( array( 'common.menu_addition','common.base_errors' ), function( $view ) { // get all categories using the category model $categories = Category::all(); $view-&gt;with( 'categories', $categories ); }); </code></pre> <p>A composer is used to pass the same set of data or to carry out the same set of tasks for a set of views. </p> <p>I am sure this will sort you out ;)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload