amiryousefi / laravel-permission Goto Github PK
View Code? Open in Web Editor NEWEasy and flexible Laravel authorization and roles permissions management
License: MIT License
Easy and flexible Laravel authorization and roles permissions management
License: MIT License
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?
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()
When session time out. The page only showed 401 Unauthorized not redirected to login page
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');
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'],
]
When there is an as
attribute in the route group but routes in that route group do not have a name, the name
column in the permissions
table is not filled right and because of that, we get a duplicate entry error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.