Laravel route Resource breaks another route - php

When I use my route like this, the test route is working fine.
Route:-
Route::group(array('namespace' => '\User'), function () {
Route::get('user/my-favorite','UserController#myFavorite');
Route::get('user/test','UserController#test'); // is working
Route::resource('user', 'UserController');
Route::group(['middleware' => ['auth']], function () {
Route::get('user/planed',['as' => 'user.planed', 'uses' => 'USerController#planed']);
.
.
.
.
But when I want to use it like following, it shows a blank page :
Route::group(array('namespace' => '\User'), function () {
Route::get('user/my-favorite','UserController#myFavorite');
Route::resource('user', 'UserController');
Route::group(['middleware' => ['auth']], function () {
Route::get('user/planed',['as' => 'user.planed', 'uses' => 'UserController#planed']);
Route::get('user/test','UserController#test'); // is not working
.
.
.
.
What is my mistake?

Because the call to test is intercepted by
Route::resource('user', 'UserController');
because if you check the routes in the console with
$> php artisan route:list
you'll see it includes
GET|HEAD | user/{user}
and then your first route
Route::get('user/test','UserController#test'); // is not working
is never reached. Try to put it BEFORE the other line.

I thing the issue in naming the route check This
Try like this
Route::group(array('namespace' => '\User'), function () {
Route::get('user/my-favorite','UserController#myFavorite');
Route::resource('user', 'UserController');
Route::group(['middleware' => ['auth']], function () {
Route::get('user/planed','UserController#planed'])->name('user.planed');
Route::get('user/test','UserController#test'); // is not working
Just replace
Route::get('user/planed',['as' => 'user.planed', 'uses' => 'UserController#planed']);
With
Route::get('user/planed','UserController#planed'])->name('user.planed');

Related

fetching route from vendor through routes/web.php

I have this route included in my web.php in my routes folder.
Route::group(['prefix' => 'admin','namespace'=>'Admin', 'middleware' => 'admin', 'as' => 'admin.'], function () {
Route::group(['prefix' => 'filemanager'], function () {
\UniSharp\LaravelFilemanager\Lfm::routes();
});
});
My issue is whenever I run php artisan route:list I get the following error:
Class App\Http\Controllers\Admin\UniSharp\LaravelFilemanager\Controllers\LfmController does not exist
The Lfm controller is inside my vendor folder and I've been scouting around the internet for a solution and applied many different ways for the route change and the only way I got it to work is by using the route provided by default from the package. But if I use that, I use lose my admin authentication I'm hoping someone could give me some insight as to what I'm doing wrong here?
I would really appreciate that! Thank you in advance.
I came up with this solution. I am using Laravel 5.4
Instead of putting the code in routes/web.php, put it in RouteServiceProvider, so the default namespace is not set yet;
protected function mapWebRoutes()
{
Route::group(['prefix' => 'laravel-filemanager', 'middleware' => ['web', 'auth']], function () {
\UniSharp\LaravelFilemanager\Lfm::routes();
});
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/web.php');
});
}
For laravel 5.6 and above,
Go to config/lfm.php and set 'use_package_routes' to false.
In routes/web.php use the following routes (this is an example, might change adhering to your prefix etc.):
Route::group(['prefix' => 'admin','namespace'=>'Admin', 'middleware' => 'admin', 'as' => 'admin.'], function () {
Route::get('/filemanager', '\UniSharp\LaravelFilemanager\Controllers\LfmController#show')->name('show');
Route::any('/filemanager/upload', '\UniSharp\LaravelFilemanager\Controllers\UploadController#upload')->name('unisharp.lfm.upload');
Route::get('/filemanager/errors', '\UniSharp\LaravelFilemanager\Controllers\LfmController#getErrors')->name('getErrors');
Route::get('/filemanager/jsonitems', '\UniSharp\LaravelFilemanager\Controllers\ItemsController#getItems')->name('getItems');
Route::get('/filemanager/move', '\UniSharp\LaravelFilemanager\Controllers\ItemsController#move')->name('move');
Route::get('/filemanager/domove', '\UniSharp\LaravelFilemanager\Controllers\ItemsController#move')->name('domove');
Route::get('/filemanager/newfolder', '\UniSharp\LaravelFilemanager\Controllers\FolderController#getAddfolder')->name('getAddfolder');
Route::get('/filemanager/folders', '\UniSharp\LaravelFilemanager\Controllers\FolderController#getFolders')->name('getFolders');
Route::get('/filemanager/crop', '\UniSharp\LaravelFilemanager\Controllers\CropController#getCrop')->name('getCrop');
Route::get('/filemanager/cropimage', '\UniSharp\LaravelFilemanager\Controllers\CropController#getCropimage')->name('getCropimage');
Route::get('/filemanager/cropnewimage', '\UniSharp\LaravelFilemanager\Controllers\CropController#getNewCropimage')->name('getCropimage');
Route::get('/filemanager/rename', '\UniSharp\LaravelFilemanager\Controllers\RenameController#getRename')->name('getRename');
Route::get('/filemanager/resize', '\UniSharp\LaravelFilemanager\Controllers\ResizeController#getResize')->name('getResize');
Route::get('/filemanager/doresize', '\UniSharp\LaravelFilemanager\Controllers\ResizeController#performResize')->name('performResize');
Route::get('/filemanager/download', '\UniSharp\LaravelFilemanager\Controllers\DownloadController#getDownload')->name('getDownload');
Route::get('/filemanager/delete', '\UniSharp\LaravelFilemanager\Controllers\DeleteController#getDelete')->name('getDelete');
Route::get('/filemanager/demo', '\UniSharp\LaravelFilemanager\Controllers\DemoController#index')->name('getDelete');
});

Controller changes does not reflect

I have a problem. I tried to change the controller but when I open the route it doesn't reflect with the latest controller? Any idea?
Controller
public function indexApplication(){
return "testing";
}
Api.php
Route::group(['prefix' => '/claim'], function(){
Route::get('/test', ['as' => 'claim.test', 'uses' => 'ClaimController#indexApplication']);
}
Response from rest client

Skipping a middleware for a particular route inside a route group in Laravel

I Want to skip the middleware for a particular route in a route group. How can I do this?
Route::group(['prefix' => 'testgroup','middleware' => ['login.oauth']],function (){
Route :: get('/', 'testController#index');
Route :: get('/api','testController#apiCall');
});
I want to skip the 'login.oauth' middleware for the Route :: get('/api','testController#apiCall')
Please keep that testgroup function must be accessible to all routes and middleware function to particular(some other route) in the same function
Route::group(['prefix' => 'testgroup'], function () {
Route::group(['middleware' => ['login.oauth'], function() {
Route :: get('/', 'testController#index');
});
Route :: get('/api','testController#apiCall');
});
Just create a second group without the middleware:
Route::group(['prefix' => 'testgroup','middleware' => ['login.oauth']],function (){
Route :: get('/', 'testController#index');
});
Route::group(['prefix' => 'testgroup'],function (){
Route :: get('/api','testController#apiCall');
});

Laravel: how to use /admin

I want to create pages for admin and I want to use dashboard in localhost:8000/admin url...but the page is showing a display Not Found Error.
Please tell me what should I do to resolve this
You need somethig like this in your /app/Http/routes.php
Route::group(['prefix' =>'admin', 'namespace' => 'admin', 'middleware' => 'auth'], function() {
Route::get('/', 'AdminController#index');
// .....
});

Using Route Prefixes in Lumen

From the Lumen 5.2 docs:
The prefix group attribute may be used to prefix each route in the
group with a given URI. For example, you may want to prefix all route
URIs within the group with admin:
$app->group(['prefix' => 'admin'], function () use ($app) {
$app->get('users', function () {
// Matches The "/admin/users" URL
});
});
My code:
$app->group(['prefix' => 'v1'], function () use ($app) {
$app->get('lessons', function () {
['as' => 'lessons.index', 'uses' => 'LessonsController#index'];
});
});
This returns a 200 but it is clearly not calling the index() method on the LessonsController.
I have also tried this:
$app->group(['prefix' => 'v1'], function () use ($app) {
$app->get('lessons', ['as' => 'lessons.index', 'uses' => 'LessonsController#index']);
});
Results in ReflectionException in Container.php line 738: Class LessonsController does not exist
I am currently using prefixes like this:
$app->group(['namespace' => "App\Http\Controllers", 'prefix' => 'v1'], function($app){
$app->get('/lessons', 'LessonsController#index');
});
Which works fine in my version of Lumen. You would access the url /v1/lessons and it is handled by the index() method inside the LessonsController
Note: It would appear that the Lumen documentation misses out that in order to do this you require the 'namespace' => "App\Http\Controllers" key value pair in order for this to work.

Categories