I want to remove Laravel Package routes and add new ones.
I installed this package https://github.com/jeremykenedy/laravel-roles on my Laravel 6.X application, I wanted to disable the routes so I would like to add a prefix of admin/ before the set routes...
Changing the routes in vendor folder doesn't help because it will get updated and gone if you run composer update, any idea on how to solve this issue, other than forking the repo?
I didn't have time to actually scan through all of the environment variables that you can configure in the package. I would recommend to check if there are any config values that you can override first. However, if you can't, then i am sure you could copy the routes and put it in your web.php
<?php
/*
|--------------------------------------------------------------------------
| Laravel Roles And Permissions Web Routes
|--------------------------------------------------------------------------
|
*/
Route::group([
'middleware' => ['web'],
'prefix' => 'admin',
'as' => 'laravelroles::',
'namespace' => 'jeremykenedy\LaravelRoles\App\Http\Controllers',
], function () {
// Dashboards and CRUD Routes
Route::resource('roles', 'LaravelRolesController');
Route::resource('permissions', 'LaravelPermissionsController');
// Deleted Roles Dashboard and CRUD Routes
Route::get('roles-deleted', 'LaravelRolesDeletedController#index')->name('roles-deleted');
Route::get('role-deleted/{id}', 'LaravelRolesDeletedController#show')->name('role-show-deleted');
Route::put('role-restore/{id}', 'LaravelRolesDeletedController#restoreRole')->name('role-restore');
Route::post('roles-deleted-restore-all', 'LaravelRolesDeletedController#restoreAllDeletedRoles')->name('roles-deleted-restore-all');
Route::delete('roles-deleted-destroy-all', 'LaravelRolesDeletedController#destroyAllDeletedRoles')->name('destroy-all-deleted-roles');
Route::delete('role-destroy/{id}', 'LaravelRolesDeletedController#destroy')->name('role-item-destroy');
// Deleted Permissions Dashboard and CRUD Routes
Route::get('permissions-deleted', 'LaravelpermissionsDeletedController#index')->name('permissions-deleted');
Route::get('permission-deleted/{id}', 'LaravelpermissionsDeletedController#show')->name('permission-show-deleted');
Route::put('permission-restore/{id}', 'LaravelpermissionsDeletedController#restorePermission')->name('permission-restore');
Route::post('permissions-deleted-restore-all', 'LaravelpermissionsDeletedController#restoreAllDeletedPermissions')->name('permissions-deleted-restore-all');
Route::delete('permissions-deleted-destroy-all', 'LaravelpermissionsDeletedController#destroyAllDeletedPermissions')->name('destroy-all-deleted-permissions');
Route::delete('permission-destroy/{id}', 'LaravelpermissionsDeletedController#destroy')->name('permission-item-destroy');
});
If you want to keep your web.php clean, then create a file at routes/laravel-permissions.php and then in your RouteServiceProvider load the routes as follow,
protected function mapLaravelPermissionRoutes()
{
Route::prefix('admin')
->as('laravelroles::')
->middleware('web')
->namespace('/jeremykenedy\LaravelRoles\App\Http\Controllers')
->group(base_path('routes/laravel-permissions.php'));
}
If you do load it this way, then make sure that you remove the grouping from your laravel-permissions.php i.e. remove the following code
Route::group([
'middleware' => ['web'],
'prefix' => 'admin',
'as' => 'laravelroles::',
'namespace' => 'jeremykenedy\LaravelRoles\App\Http\Controllers',
], function () {
Now you just need to map the method as follow
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
$this->mapLaravelPermissionRoutes();
}
Related
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.
I have two kind of routes, admin routes and frontend routes.
The frontend routes
Route::get('{locale?}/', ['uses' => '\App\Http\Controllers\loadViewController#home']);
Route::get('{locale?}/{page}', ['uses' => '\App\Http\Controllers\loadViewController#index']);
Route::get('{locale?}/{template?}/{page}', ['uses' => '\App\Http\Controllers\loadViewController#detail']);
The backend routes
Route::prefix('admin/dashboard')->group(function () {
Route::get('/', 'DashboardController#index')->name('dashboard');
});
Now when i type admin/dashboard or api/admin, laravel uses the frontend routes to load the views, while i want the backend views to be loaded.
So to filter out the backend routes i tried this
Route::group(['where' => ['page' => '^(?!admin|api)$', 'template' => '^(?!admin|api)$']], function ({
Route::get('{locale?}/', ['uses' => '\App\Http\Controllers\loadViewController#home']);
Route::get('{locale?}/{page}', ['uses' => '\App\Http\Controllers\loadViewController#index']);
Route::get('{locale?}/{template?}/{page}', ['uses' => '\App\Http\Controllers\loadViewController#detail']);
});
which obviously did not work
Also the frontend routes should not have something like /website, they should all start with /
My question is: How can i load the backend and frontend routes separately without interfering when called, even if they have the same url length in terms of parameters, keep in mind that the admin routes always start with /admin or /api.
Note: i can't put the backend routes before the frontend routes
Thanks in advance!
If you want to you could put a constraint on the locale route parameter:
Route::pattern('locale', '^(?!(api|admin)$)(\w*)');
You can put this in the boot method of you RouteServiceProvider and it will now not allow the locale route parameter to match for 'api' or 'admin'.
You can register seperate routes in RouteServiceProvider. Following is how you can do it.
Inside RouteServiceProvider.php do:
public function map()
{
$this->mapFrontendRoutes();
$this->mapAdminRoutes();
}
Definition of mapFrontendRoutes():
protected function mapFrontendRoutes()
{
Route::prefix('{locales?}')
->middleware('frontend')
->namespace($this->namespace.'\Frontend')
->group(base_path('routes/frontend.php'));
}
Definition of mapAdminRoutes():
protected function mapAdminRoutes()
{
Route::prefix('admin')
->middleware('admin')
->namespace($this->namespace.'\Admin')
->group(base_path('routes/admin.php'));
}
I personally find this very useful, helps to declare interference free and logical routes. Open to feedback.
The simple way is to group both url's as separate groups. Example as follows :
Route::group(['prefix' => 'admin', 'as' => 'admin'], function () {
Route::post('/dashboard', 'AdminController#dashboard');
});
Route::group(['prefix' => 'home', 'as' => 'home'], function () {
Route::get('/record/{id}', 'HomeController#getRecord');
});
I ran deb deploy and it got down to this point.
The command "/usr/bin/php ~/NetTube/releases/1/artisan optimize" failed.
Exit Code: 1 (General error)
Host Name: 68.183.20.108
================
Configuration cache cleared!
Configuration cached successfully!
Route cache cleared!
In Route.php line 917:
Unable to prepare route [api/user] for serialization. Uses Closure.
I've looked into this and it seems that I can't use closures with routes, which is fine. I'm just not sure how to prevent closures.
This is my web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
// Route::get('/', function () {
// return view('welcome');
// });
Route::get('/','HomeController#index')->name('home');
Auth::routes();
// Route::get('/home', 'HomeController#index')->name('home');
Route::group(['middleware' => ['auth']], function(){
Route::get('/upload','VideoUploadController#index');
Route::get('/channel/{channel}/edit','ChannelSettingsController#edit');
Route::put('/channel/{channel}/edit','ChannelSettingsController#update');
});
Route::get('/channel/{channel}','ChannelController#index');
Route::get('/{channel}','ChannelController#index');
I have tried putting the routes not in a group with
Route::get('/upload', [
'uses' => 'VideoUploadController#index',
'middleware' => ['auth'],
]);
Route::get('/channel/{channel}/edit', [
'uses' => 'ChannelSettingsController#edit',
'middleware' => ['auth'],
]);
Route::put('/channel/{channel}/edit', [
'uses' => 'ChannelSettingsController#update',
'middleware' => ['auth'],
]);
I am running laravel 6.17.1. I hope I gave enough information to anybody that can help.
the problem resides on the routes\api.php.
Do something like Route::middleware('auth:api')->get('/user', 'MyProfileController#index');. This route needs to be binded to a controller. If you don't need the route, comment or delete it.
I am building a system where the user creates a project and then the project has pages and routes.
I am working out the URL structure now and in Laravel is there a good way with middle ware to get the project information. Here's what I am thinking for the route structure:
{project}/
{project}/something
{project}/something/else
{project}/settings
Route::group with a prefix seems like the best way to include all the middleware. Is there a way I can write a middleware class to check if the {project} exists and then send the data to the view?
Route::group([
'prefix' => '{project}',
'middleware' => [
'auth',
'getprojectstuffandthings'
], ], function () {
// project routes
}
]);
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.