Using middleware route filer in Entrust for Laravel - php

I have used Entrust for laravel, everything works fine until I used the middleware route filter.
Like I said everything works fine apart from the middlware filter. I have added the routemiddleware array to kernel. So this is basically what the filter looks like, same thing that is found in the docs:
Route::group(['prefix' => 'admin', 'middleware' => ['role:admin']], function() {
Route::get('/', 'AdminController#welcome');
Route::get('/manage', ['middleware' => ['permission:manage-admins'], 'uses' => 'AdminController#manageAdmins']);
});
But I've got this error:
ReflectionException in Container.php line 779: Class role:admin does
not exist

after you finish installation, you need run composer dump-autoload ,and make sure you follow every step of the doc

Related

PermissionManager for Backpack Laravel -> I want to protect the Routes to Users that only can Edit Permissions

I made this in:
/vendor/backpack/permissionmanager/src/routes/backpack/permissionmanager.php
Route::group([
'namespace' => 'Backpack\PermissionManager\app\Http\Controllers',
'prefix' => config('backpack.base.route_prefix', 'admin'),
'middleware' => ['web', backpack_middleware()],
], function () {
Route::group(['middleware' => ['can:edit permissions']], function () { <---- I added this code
Route::crud('permission', 'PermissionCrudController');
Route::crud('role', 'RoleCrudController');
Route::crud('user', 'UserCrudController');
}); <---- I added this code
});
It doesn't work
But I know is not a good idea to do it like this, touching the vendor folder
How can I handle this situation?
Also I've tried to put that code inside the routes of Backpack (/routes/backpack/custom.php), with no results
Indeed, changing things in the vendor directory is a big no-no. But you can easily do the same in your app. You can see in this package's docs, under overwriting functionality that there's an easier solution for that:
Create a routes/backpack/permissionmanager.php file. Then Backpack will load YOUR file, instead of the one in the package.
Remember to include ALL routes from the vendor file and all your overwrites too. The file in the vendor will no longer be used.

Laravel route conflict with resource routes

I'm using this route in a project hosted in my local mac pc, it is working, but when i have uploaded that to an Ubunto server route conflict occurred.
Route::group(['prefix'=>'report', 'middleware' => ['auth','session', 'complete_profile']], function() {
Route::get('/get_query', 'ReportController#get_queries');
});
Route::group(['middleware' => ['auth','session', 'complete_profile']], function(){
Route::resource('report','ReportController');
});
for example when i use form first route report/get_query in online ubunto server it goes to the show($id) method of that controller, But in local its working.
What should I do with this ?
Route::group(['prefix'=>'report', 'middleware' => ['auth','session', 'complete_profile']], function() {
Route::resource('/','ReportController',['except' => ['show']]);
Route::get('/get_query', 'ReportController#get_queries');
});
Resource route has predefined route for http methodes. For example reporte resource has route:
Route::get('report/{report}','ReportController#show');
Solution is to exclude some methodes (routes from restfull resource), or to make some routes that wont conflict with route resource.
You can see what route you have registered by running:
php artisan route:list
Also one route group for report is enough just put '/' in resource route.

Multi auth for laravel 5.2 use middleware

I want to use multi authenticate in Laravel 5.2. But I found a strange problem.
Here is my code in route.php.
However I can not get $errors in the login.blade.php, it just returns null.
<?php
Route::group(['middleware' => ['web'], 'namespace' => 'Admin', 'prefix' => 'admin'], function () {
Route::auth();
});
?>
But when I remove the web middleware, it works.
<?php
Route::group(`enter code here`['namespace' => 'Admin', 'prefix' => 'admin'], function () {
Route::auth();
});
?>
I don't know why. My understanding is that when I want to use the session, I must use the web middleware.
Because on Laravel 5.2 the web middleware is automatically applied, your routes in routes.php are grouped with prefix App\Http\Controllers and web middleware. You can find this definition on mapWebRoutes() method of the RouteServiceProdiver.php.

Laravel make:auth problems, can't view the premade login or register page

I've created a laravel 5.2 project. I added a database, and some basic views and controllers (Note: I think this is my problem). I then ran the artisan make:auth command. It ran successfully. Despite me already having a login and home view and controller.
I can view laravel's premade 'home' page on my localhost. But once I click the login or register link, things break and I get,
"No supported encrypter found. The cipher and / or key length are invalid."
I've de-bugged this and insured my keys are correct and in the appropriate places.
This is my routes.php
Route::get('/', function () {
return view('welcome');
});
Route::group(['middleware' => ['web']], function () {
//
});
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/home', 'HomeController#index');
});
I obviously have no route here for login or register, but shouldn't make:auth create routing behind the scenes? From what I've read, this should have worked out of the box. What am I missing here? Any help would be great,
Thanks.
Run
$ php artisan key:generate
I have resolved my problem.
I had originally set the key in my .env file to
APP_KEY=854uQ9...(random 32 bit key)
I had also set config/app.php to
'key' => env('854uQ9...(same 32 bit key as above)')
NOTE the missing ''APP_KEY''. Once I changed config/app.php back to
'key' => env('APP_KEY', 'SomeRandomString'),
the links worked. I can now change 'SomeRandomString' to my app key, but as the .env file is checked first, I assume this can be left as is.
Thanks for the replys.

Laravel-5 / Sentinel disabling default routes

I am using Laravel5 with Sentinel and have disabled the default routes within the sentinel.php config file:
'routes_enabled => false'
I am using the "rydurham/sentinel": "~2.2" composer package.
Now I am trying to create my own routes for the authentication system to follow. I managed to get my own custom login page displaying correctly using the following code:
Route::get('login', ['as' => 'sentinel.login', function()
{
return View::make('Auth.login');
}]);
However, i'm having a problem trying to get the route to work when the login form is posted. Here's my route:
Route::post('login', ['as' => 'sentinel.session.store', 'uses' => 'Sentinel\Controllers\SessionController#store', function()
{
}]);
I'm getting the following error:
ReflectionException in Container.php line 736: Class App\Http\Controllers\Sentinel\Controllers\SessionController does not exist
I managed to fix it by adding a \ in the route path to Sentinel Controller:
Route::post('login', ['as' => 'sentinel.session.store', 'uses' => '\Sentinel\Controllers\SessionController#store', function()
{
}]);

Categories