Coder Social home page Coder Social logo

laravel-permission's Introduction

Hi there ๐Ÿ‘‹

laravel-permission's People

Contributors

a-yousefi avatar aahelali avatar amiryousefi avatar asia-coder avatar hackerinos2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-permission's Issues

Help with installation

Hey, I really like the Plugin and would like to use it, but I'm having some problems with installation.
For installation I made all the following steps, but when I navigate to my assigned route with role admin, I get redirected to my 404 page.

I installed via composer and run php artisan migrate. Then I created a Seeder:

<?php

use Illuminate\Database\Seeder;
use Amir\Permission\Models\Role;

class RolesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
       	        Role::firstOrCreate(['name' => 'admin']);
		Role::firstOrCreate(['name' => 'moderator']);
		Role::firstOrCreate(['name' => 'jakob']);
		Role::firstOrCreate(['name' => 'user']);
    }
}

Then I run artisan db:seed --class=RolesTableSeeder.

Then I copied over your src/Middleware/AuthRoles.php to App\Http\Middleware\AuthRoles.php.
In App\แธจTTP\Kernel.php I registered the Middleware:

protected $routeMiddleware = [
        ...
        'auth.role' => \App\Http\Middleware\AuthRoles::class,
        ...
    ];

After I setup my routes routes\web.php:

Route::group([
    'middleware' => 'auth.role',
    'prefix' => 'test',
    'role' => 'admin',
],function (){
    Route::get('/test', 'MyTest@index');
});

And run php artisan permissions:generate.
Then I set my user profile table role_id in phpmyadmin to 1 (admin).

EDIT: After i registered the provider in config\app.php

'providers' => [
    ....
    Amir\Permission\LaravelPermissionServiceProvider::class,
    ....
],

All roles are in the db table, all permissions are in the db table and there is also the permission_role inserted in the database. Now when I goto my route /test I get redireted to 404 Page.
Can you help me?

Error when try use php artisan permissions:generate --fresh

Illuminate\Database\QueryException

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (esi.users, CONSTRAINT users_role_id_foreign FOREIGN KEY (role_id) REFERENCES roles (id)) (SQL: delete from roles)

at C:\laragon\www\esi\vendor\laravel\framework\src\Illuminate\Database\Connection.php:671

    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675| 

1 C:\laragon\www\esi\vendor\laravel\framework\src\Illuminate\Database\Connection.php:489
PDOException::("SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (esi.users, CONSTRAINT users_role_id_foreign FOREIGN KEY (role_id) REFERENCES roles (id))")

2 C:\laragon\www\esi\vendor\laravel\framework\src\Illuminate\Database\Connection.php:489
PDOStatement::execute()

id on roles table does not exist.

When migrating, this error comes up:
BadMethodCallException : Method Illuminate\Database\Schema\Blueprint::id does not exist.

this is because id on the roles schema has been set as a datatype instead of increments

For example: $table->increments('id');

Assign more then 1 role to a route

How can I assign more then one role to a route? I tried this, but its not working:

Route::group([
    'middleware' => 'auth.role',
    'role' => ['moderator', 'admin'],
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.