Depends entirely on the type of app you are trying to build. Is your app going to require multiple user roles (registered user, administrator, etc.)? If it does, you need to designate a role/permission in the database migration. If you are trying to make an admin only section for all logged in users, it's as easy as adding this in your routes.php file:
Route::group(array('before' => 'auth'), function()
{
//Insert Routes here
});
All routes added in the designated section will only be accessible if the user is logged in.
I would recommend this link to create a simple authentication/login system: https://scotch.io/tutorials/simple-and-easy-laravel-login-authentication
Good luck.
-- If you are trying to this via permission levels.
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('email', 320);
$table->string('password', 64);
$table->integer('permission')->default(1)->unsigned();
$table->rememberToken();
$table->timestamps();
});
In your routes.php
Route::group(array('before' => 'auth'), function()
{
if(Auth::user()->permission > 1)// Change 1 to permission level below req.
{
// Specify Routing here
}
});
Thanks a lot. But in my app will be only exist:
Registered users.
Me as Admin.
What would you do if you were me?
I thought about it:
Route::filter('admin', function()
{
if (Auth::user()->id != 1)
return Redirect::to('/');
} );
you can solve it in this way...but it's a very small solution. I would create a column like "admin".
if(Auth::user()->admin !== 1)
return Redirect::to('/');
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community