Support the ongoing development of Laravel.io →
Authentication Security Session
Last updated 2 years ago.
0

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.

  1. In your user's migration file, add a permission entry for the database
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
	}
});
Last updated 9 years ago.
0

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('/');
} );
Last updated 9 years ago.
0

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('/');
0

Sign in to participate in this thread!

Eventy

Your banner here too?

DiegoHeras diegoheras Joined 26 Dec 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.