I have a problem with my Laravel project. I created an admin route group (domain.co/admin/). The root /admin/ at one point was working then i added a few more pages have updated composer, installed doctrine/dbal, and installed chart.js since then. Now for some reason the /admin/ route no longer works but all other routes work perfectly normal.
my web.php routes look like this:
Route::get('/', function () {
return view('home');
});
Auth::routes(); // tried commenting this out
Route::middleware(['web','auth','rolecheck:Super'])->prefix('admin')-
>group(function(){
Route::get('/', 'AdminController#index');
Route::get('/test', 'AdminController#index');
Route::get('/test2', 'AdminController#test');
....
});
...
There are more route groups that also work
/admin/ gives me a permission error. /admin/test/ /admin/test2/ work fine
here is the controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AdminController extends Controller
{
public function index(){
echo '2';
//return view('admin.dashboard');
}
public function test(){
echo '1';
}
}
.htaccess doesnt show anything weird (default from laravel). I have also tried clearing caches.
I found nothing in the /etc/httpd conf files.
I have tired looking through all the code for the word 'admin' and can't find anything that is pointing to why its saying permission denied.
If i change the prefix to 'admins' it works so i am guessing some part of laravel is blocking the admin/ route. Where else can i look to see where its being blocked.
Check your public folder if you have 'admin' folder there, then rename it. In my case it was a reason of such a behavior.folders structure
Check the config/auth file in your laravel directory and check the guards and providers array in it default look like this.
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
Copy/Paste these files (.htaccess, index.php, favicon.ico, robots.txt) from the /public folder to the /public/admin folder.
Edit the /public/admin/index.php file and add "/.." to all 3 required php files:
from
require __DIR__.'/../vendor/autoload.php';
to
require __DIR__.'/../../vendor/autoload.php';
Related
I have a problem with my routes on the server and using laravel 8, with a version of php 8.0.6
When developing locally I have no problem with the routes, everything is normal, but when uploading the project to the server (to which I do not have access but someone else uploads the changes from the repository) it throws me the following error in some views...
Error 404
In my code I have the routes declared as follows in the routes/web.php file...
Route::get('/home', 'PagesController#home');
Each view has a function that comes from the controller...
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use PhpParser\Node\Expr\FuncCall;
class PagesController extends Controller
{
public function home()
{
$page_title = 'Dashboard';
return view('pages.dashboard', compact('page_title'));
}
}
On the other hand, each route can be accessed through a menu aside
// Aside menu
return [
'items' => [
// Dashboard
[
'title' => 'Dashboard',
'root' => true,
'icon' => 'media/svg/icons/Design/Layers.svg', // or can be 'flaticon-home' or any flaticon-*
'page' => '/home',
'new-tab' => false,
]
]
]
I tried :
correct writing to avoid mistakes
change "/" in each affected path
note: they told me the server was in strict mode
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();
}
I have a route in my app/routes.php i.e.
Route::get('sitemap', [
'as' => 'sitemap',
'uses' => 'PageController#sitemap'
]);
And sitemap.xml in public/ folder.
When I hit the URL http://example.com/sitemap it returns the content written in public/sitemap.xml rather than executing a specified route from app/routes.php
Although, http://example.com/index.php/sitemap works fine.
I need the standard solution for this.
I've followed the instructions at https://github.com/strebl/ldap-auth with a brand new laravel project and I can't seem to get it to work. I have done the following:
Added the following line to app.php
Ccovey\LdapAuth\LdapAuthServiceProvider::class
Changed the driver to LDAP in auth.php
'providers' => [
'users' => [
'driver' => 'ldap',
'model' => App\User::class,
]
],
I've also created a adladap.php file that I haven't posted here.
I have also added middleware group in order to make sure the user was authenticated.
Route::group(['middleware' => 'auth'], function () {
Route::get('/test', function(){ return "Test";});
}
However when I try to go to the test route I get the following error
InvalidArgumentException in CreatesUserProviders.php line 40:
Authentication user provider [ldap] is not defined.
I'm sure there's some simple configuration that I've been looking over but for the life of me I can't figure out what it is.
If you are trying to do adminless LDAP, this might be of interest:
laravel-simple-ldap-auth
In my Laravel app I'm splitting the front end and back end code into folder. These are app/Http/Controllers/BackEnd and app/Http/Controllers/FrontEnd. Rather than type all that out on every file I thought it would be easier to define two namespaces, BackEnd and FrontEnd. I've edited my composer file to this:
"autoload": {
"classmap": [
"app/Models",
"database"
],
"psr-4": {
"App\\": "app/",
"BackEnd\\": "app/Http/Controllers/BackEnd",
"FrontEnd\\": "app/Http/Controllers/FrontEnd"
}
},
I then ran composer autodump and set up my route file like this:
Route::group(['prefix' => 'webman', 'middleware' => 'auth', 'namespace' => 'BackEnd'], function()
{
Route::get('/', ['as' => 'webmanHome', 'uses' => 'HomeController#index']);
});
But when I browse to localhost:8000/webman/ I just get an error, Class App\Http\Controllers\BackEnd\HomeController does not exist. The controller does exist, this is the file:
<?php namespace BackEnd;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class HomeController extends Controller {
/**
* Display the admin home page, showing the front-end menu and "apps" as links to other sections of the ACP.
*
* #param Reqeust $request
*
* #return View
*/
public function index(Request $request)
{
return view('backend.index');
}
}
I've checked vendor/composer/autoload_psr4.php to make sure that the namespace is being defined and it is, this is in the array returned 'BackEnd\\' => array($baseDir . '/app/Http/Controllers/BackEnd'),.
Strangely if I use <?php namespace App\Http\Controllers\BackEnd; at the top of HomeController.php then everything works, why? What am I missing? Why can't autoload find the file with just BackEnd?
When setting namespace in Route::group() it is actually appending that to App\Http\Controllers. What you could do is remove it and reference the full path like so:
Route::group(['prefix' => 'webman', 'middleware' => 'auth'], function()
{
Route::get('/', ['as' => 'webmanHome', 'uses' => '\BackEnd\HomeController#index']);
});
Try changing/commenting the below line in RouteServiceProvider.php
protected $namespace = 'App\Http\Controllers';
There's an interesting and easy way to get around this... Service Providers.
When the route file is loaded via a provider, the 'App\Http...' is not enforced.
public function boot()
{
$this->loadRoutesFrom(app_path('Your/Model/routes.php'));
}
Keep in mind no middleware is attached either. Your route group will have to specify a 'web' middleware or you'll go nuts wondering why validation, etc, isn't working anymore....(been there!)
It's a cool way to go about it anyway, using providers leads to more modular code and re-use.