Laravel 5.5 Route groups - laravel-5

I was having this in my website using Laravel 5.3 :
Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware'=>'auth'], function(){
Route::resource('posts', 'PostsController');
});
This lets me go to the admin panel using: mywebsite/public/admin/posts.
Now, when I migrated the site to Laravel5.5 I got this error Route[admin.posts.create] not defined when i attempt to open the link Create post which was working fine before.
I know that routing system has changed but I did not know how to have such links in new Laravel5.5. I tried url instead of route but I got the same error. I also checked the new documentation but I did not get exactly how to have the same link system.
Can anyone have a better explanation of this new routing system? (I have to migrate the site to 5.5).

Laravel names resource routes by default, you can check them by running php artisan route:list
If you want to override them for any reason you can pass in an array when you define the route and override each individual route name like so:
Route::resource('posts', 'PostsController', ['names' => [
'create' => 'admin.posts.build'
]]);

Related

route model binding doesn't work anymore with api package devolpment in in Laravel 8.x

I created an api which is delivered with package development composer. in Laravel 7 it was possible to add the route model binding with:
Route::group(['namespace' => 'Acme\Package\app\Http\Controllers\Api'], function () {
// fomer possibility:
Route::apiResource('api/comments/', 'CommentController')->middleware('bindings');});
In Laravel 8 that's not possible anymore. I've tried almost everything the last days, but either the route-model-binding is not working, or the class can't be found:
Target class [bindings] does not exist.
I really hope someone can post an answer to the problem, or a hint or anything useful.
many thanks in advance
EDIT:
Thanks for the answers, including the middleware in the Route::group like mentioned:
Route::group(['namespace' => 'Acme\Package\app\Http\Controllers\Api', 'middleware' => 'Illuminate\Routing\Middleware\SubstituteBindings']
did it.
In Laravel 8 the alias for this middleware has been removed. You can either use it by its full class name
Illuminate\Routing\Middleware\SubstituteBindings
or add the alias back in to your app/Http/Kernels.php in $routeMiddleware as follows:
protected $routeMiddleware = [
'auth' => Authenticate::class,
'bindings' => Illuminate\Routing\Middleware\SubstituteBindings,
/*...*/
You have to be careful if you are relying on values in someones application to exist. I could use a different name/alias for that middleware if I wanted to in my HTTP Kernel. You should be using the FQCN for that middleware that comes from the framework when referencing it like that.
In a default Laravel 8 install there is no middleware named/aliased as 'bindings'. It is referenced by its FQCN, Illuminate\Routing\Middleware\SubstituteBindings, which is how you should probably be referencing it from a package.
You can provide a config file for someone to alter these things if you would like. Then you can use your configuration to know which middleware to reference.

After share website on server, only mainpage works

I have a website and when I share it on trial server everything was ok. After I bought the domain so I must upload everything files again. Problem is that routung doesn't work correctly. I see only main page and whe I try open other page I see error 404. Chmod I change to 777 (public_html and folder with other files).
For example:
//This works
Route::get('/', [
'uses' => 'FrontendController#rules',
'as' => 'en.rules'
]);
//This doesn't work
Route::get('/rules', [
'uses' => 'FrontendController#rules',
'as' => 'en.rules'
]);
I found this https://laracasts.com/discuss/channels/laravel/laravel-5-only-home-page-route-working-on-live-server but it doesn't work too. Any idea?
Please make sure that you have published the providers and tag files if using third-party modules.
php artisan vendor:publish

Laravel 5.3 NotFoundHttpException

I'm trying to setup a Laravel 5.3 project. I have create the project and starting the 'localhost//public' shows the welcome screen just fine.
When adding a test entry in the web.php file like
Route::get('about', function () {
return view('welcome');
});
An then trying to access this as 'localhost//public/about' I get this NotFoundHttpException in RouteCollection.php line 161: error. I'm really puzzled as to whats wrong.
In the 5.2 version, with the routes.php, it worked perfectly fine.
Regs.,
Erik
NotFoundHttpException means Laravel can't found the requested route. Hence, you are trying to access something which doesn't exist that's why it is throwing NotFoundHttpException.
Try to access your route like
localhost/public/about
Well its a strange story when using artisan route:list the about neatly pops up. However when accessing through Chrome i wasn't able to load it. I have dropped the whole www directory and started afresh. Now it works. Must have been something lingering around.
Thx.,
Erik
You can try adding a 'public' prefix for the web routes in app\Providers\RouteServiceProvider.php like so:
protected function mapWebRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
'prefix' => 'public',
], function ($router) {
require base_path('routes/web.php');
});
}

How to route to a controller method in Laravel Moduler development?

I am using "artem-schander/l5-modular": "dev-master" for laravel moduler development.
For example i create an Admin module.
Folder structure is App/Modules/Admin.
So controller related to Admin modules placed under App/Modules/Admin/Controllers/ directory.
All routes related to Admin module are placed in App/Modules/Admin/routes.php file.
Here how it looks
Route::group(array('module' => 'Admin', 'middleware' => ['web'],'namespace' => 'App\Modules\Admin\Controllers'), function() {
Route::resource('admin', 'AdminController');
});
All view files related to admin module placed in App/Modules/Admin/Views folder.
I am trying to access Admin's index view using this route
Route::get('/', 'AdminController#index');
This route is place in laravel default routes.php file.
and when i browse ,I am getting this error
Class App\Http\Controllers\AdminController does not exist
From this i understood , laravel looking AdminController in its default path.
How can i overcome this challenge ?
You can access a controller by full qualified namespace if it is not in default path.
Try:
Route::resource('admin', '\App\Modules\Admin\Controllers\AdminController');
I have found two way to do it.
First Option
Changing the $namespace in RouteServiceProvider.php .
For me
private $namespace='\App\Modules';
So for Admin module i can use route as
Route::get('/', 'Admin\Controllers\AdminController#index');
I think this is bad idea to change Laravel's default value.
Second Option
Providing full path of the Controller.
So route would be like this
Route::get('/','\App\Modules\Admin\Controllers\AdminController#index');

Laravel 5 ElFinder Class replace-this-with-your-middleware does not exist error while browse server

I have configured elfinder in Laravel 5 and also using CKEditor. Everything was fine till until I click on browse server button and then I got "Class replace-this-with-your-middleware does not exist" error.
I have searched the web but I did not find any suitable answer. What can I try next?
You should write your middleware name in elfinder configs.
for example:
'route' => [
'prefix' => 'elfinder',
'middleware' => 'auth'/*replace-this-with-your-middleware*/, //Set to null to disable middleware filter
],
image

Resources