Farshad
Farshad

Reputation: 2000

how to add an admin in laravel 5.1 auth manually from database

any body has any idea how to pass the authentication of laravel ? or to add an admin from database or the source code ? assuming you have created an admin panel and an admin user but you lost your database and now you just want to create a new admin user for your panel . i used default laravel authentication and middle ware for admin panel . here is the middle ware added in kernel.php

        'admin' => \App\Http\Middleware\AuthAdmin::class,

and here we got role controller

 if(Auth::user()->isSuperAdmin()) {
        $objects = Role::select($this->dt_fields_db)->where('id','<>',1)->where('id','<>',3);
    } else {
        $objects = Role::select($this->dt_fields_db)->where('id','>',3);
    }

Upvotes: 1

Views: 3711

Answers (2)

user320487
user320487

Reputation:

Make a new Seeder class, create a user and the super admin role, assign the role to the user and be a super admin forever and ever.

public class SuperAdminSeeder {
    public function run () {
        // modify to following commands fit your table structure
        $role = Role::create(['name' => 'super_admin'];
        $user = User::create(['email' => '[email protected]', 'password' => bcrypt('secret')]);
        DB::table('role_user')->insert(['user_id' => $user->id, 'role_id' => $role->id]);
    }
}

Call it via the command line:

php artisan db:seed --class=SuperAdminSeeder::class

Upvotes: 3

Adam Kozlowski
Adam Kozlowski

Reputation: 5906

Just run php artisan make:auth and php artisan migrate. Then, navigate your browser to http://your-app.dev/register or any other URL that is assigned to your application. These two commands will take care of scaffolding your entire authentication system.

Upvotes: 0

Related Questions