Controller changes does not reflect - php

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

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');
});

Laravel route Resource breaks another route

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');

Laravel 5.3: localhost redirected you too many times

I have 2 user roles which is superadmin and admin
I don't want admin to access of Settings Page.
I am not sure if this is the proper way.
So, here's my SettingsController.php
class SettingsController extends Controller {
public function index() {
if(Auth::user()->roles == 0) {
return redirect(url()->previous());
} else {
return view('settings.index');
}
}
}
As you can see if the roles is 0. I redirect the user to the last page they're in. I also tried to use return back();
web.php (routes)
<?php
Route::get('/', ['uses' => 'UsersController#index']);
Route::post('login', ['uses' => 'UsersController#login']);
Route::group(['middleware' => ['auth']], function() {
Route::get('logout', ['uses' => 'UsersController#destroy']);
Route::get('upline', ['uses' => 'UplinesController#index']);
Route::get('upline/create', ['uses' => 'UplinesController#create']);
Route::post('upline', ['uses' => 'UplinesController#store']);
Route::delete('upline/destroy/{id}', ['uses' => 'UplinesController#destroy']);
Route::put('upline/update/{id}', ['uses' => 'UplinesController#update']);
Route::get('upline/getdownlines/{id}', ['uses' => 'UplinesController#getDownlines']);
Route::get('downline', ['uses' => 'DownlinesController#index']);
Route::post('downline', ['uses' => 'DownlinesController#store']);
Route::delete('upline/destroy/{id}', ['uses' => 'DownlinesController#destroy']);
Route::put('downline/update/{id}', ['uses' => 'DownlinesController#update']);
Route::get('bonus', ['uses' => 'BonusController#index']);
Route::post('bonus/csv', ['uses' => 'BonusController#fileUpload']);
Route::get('settings', ['uses' => 'SettingsController#index']);
});
I have a 2nd question. Can I limit admin using middleware? If yes, how?
Any help would be appreciated.
Maybe the second option, "Limiting admin with middleware".
So you can try something like;
Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function () {
Route::get('/', 'DownlinesController#update');
});
Then
Route::group(['prefix' => 'super', 'middleware' => 'auth'], function () {
Route::get('/', 'UplinesController#index');
});
As #michael s answer suggests use middleware, his answer fails to demonstrate on how to do it (mine too, I just added more text).
Note: Laravel is big because of its documentation, USE IT!
You have 2 (or more options):
parameterized middleware
2 distinctive middlewares (one for admin, another for superadmin)
Note: use artisan to generate middleware from stubs, $ php artisan make:middleware MyNewShinyMiddleware
parametrized middleware (my pick)
Head to documentation and check out this.
Example shows exactly your problem.
public function handle($request, Closure $next, $role)
{
if (! $request->user()->hasRole($role)) { //implement hasRole in User Model
// Redirect...
// (use named routes to redirect or do 401 (unauthorized) because thats what is going on!
// abort(401) // create view in /views/errors/401.blade.php
// return redirect()->route('home');
}
//success user has role $role, do nothing here just go to another "onion" layer
return $next($request);
}
2 distinctive middlewares
simply create two middlewares and hardcode your checking routine of roles
(same as you do in your controller sample) except use $request->user()...
(routes) web.php
Route::group(['middleware' => 'role:admin'], function () {...} //parametrized
Route::group(['middleware' => 'checkRoleAdmin'], function () {...}
Route::group(['middleware' => 'checkRoleSuper'], function () {...}
Note: role, checkRoleAdmin and checkRoleSuper are "named" middlewares and you need to register them in kernel.php
Another way is yo use gates or policies which make the best sense, since you are trying to limit user. Read more here.
I use middleware based ACL for really simple projects (like one admin and no real users).
I use gates based ACL for medium projects (1-2 roles).
I use policies based ACL for "huge" projects (many roles, many users).
Also consider looking at https://github.com/Zizaco/entrust

Laravel routes not working anymore

I'm learning Laravel, and I'm busy building a site (framework version 5.1.34). I installed Homestead in September last year, initially on Windows 7 and then upgraded to Windows 10. Everything was working fine on Windows 7 and later on Windows 10 also (I had some issues on Windows 10 which I managed to sort out), but then my routes started acting strange recently. All of my routes still work, except the one now comes up with a 404 error. The route is:
Route::get('projects/{project}/nodes/{node}/tasks/create',
['uses' => 'TaskController#taskCreateShow']);
The controller function is:
public function taskCreateShow(Project $project, Node $node){
return view('tasks.create')
->with('project',$project)
->with('user',$this->user)
->with('node',$node)
->with('all_projects',$this->all_projects);
} // taskCreateShow
If I run php artisan route:list the route still shows up like all the other routes. I can add new routes, which also work fine. The model binding is defined in the RouteServiceProvider.php class in the boot function:
public function boot(Router $router)
{
parent::boot($router);
// Route model binding
$router->model('project', 'resolved7\Project');
$router->model('user', 'resolved7\User');
$router->model('node', 'resolved7\Node');
$router->model('task', 'resolved7\Task');
$router->model('io', 'resolved7\Io');
}
The only way I've been able to get this to work, is to change the route to:
Route::get('projects_1/{project}/nodes/{node}/tasks/create',
['uses' => 'TaskController#taskCreateShow']);
I've looked at the .htaccess file, and it seems fine. Does anyone perhaps know what could cause this to happen? I appreciate any help or suggestions. Thanks.
*edit: here is the routes.php file:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
*/
/*=========================================================================
* General routes
*/
Route::get('/', function(){
return redirect('index');
});
Route::get('dashboard', function(){
return 'dashboard';
});
Route::get('about', function(){
return view('about')->with('company_name', 'The Resolved 7<sup>th</sup>');
});
Route::get('index', function(){
return view('index');
});
// Route used to get images from non-public folder
Route::get('images/{filename}', function ($filename)
{
$path = storage_path() . '/profilepics/' . $filename;
$file = File::get($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
});
/* =========================================================================
* Project specific routes
* Use controller to re-use construct functions
*/
// Project specific dashboard
Route::get('projects/{project}', ['uses' => 'ProjectController#projectDashboard'])
->where('project','[0-9]+');
// Page from which to create new project
Route::get('projects/create', ['uses' => 'ProjectController#projectCreateShow']);
// Create a new project through post method
Route::post('projects', ['uses' => 'ProjectController#projectCreate']);
// Page from which to edit projects
Route::get('projects/{project}/edit', ['uses' => 'ProjectController#projectEditShow']);
// Update an existing project through put method
Route::put('projects/{project}', ['uses' => 'ProjectController#projectEdit']);
// Page from which a project deletion is confirmed
Route::get('projects/{project}/delete', ['uses' => 'ProjectController#projectDeleteShow']);
// Delete project
Route::delete('projects/{project}', ['uses' => 'ProjectController#projectDelete']);
// Page to show project details
Route::get('projects/{project}/detail', ['uses' => 'ProjectController#projectDetail']);
// Page from which to select users to add as members
Route::get('projects/{project}/members/invite', ['uses' => 'ProjectController#projectAddMembersShow']);
/* =========================================================================
* User specific routes
*/
// Page to test user
Route::get('users/{user}/test', ['middleware' => 'auth',
'uses' => 'UserController#test']);
// Page to show user
Route::get('users/{user}', ['middleware' => 'auth',
'uses' => 'UserController#show']);
// Page from which to edit user
Route::get('users/{user}/edit', ['middleware' => 'auth',
'uses' => 'UserController#showUserEdit']);
// Update an existing user through put method
Route::put('users/{user}', ['middleware' => 'auth',
'uses' => 'UserController#userEdit']);
/* =========================================================================
* Node specific routes
*/
// Page from which to view node
Route::get('projects/{project}/nodes/{node}',
['uses' => 'NodeController#nodeShow']);
// Page from which to create new node
Route::get('projects/{project}/nodes/create',
['uses' => 'NodeController#nodeCreateShow']);
// Create a new node through post method
Route::post('projects/{project}/nodes',
['uses' => 'NodeController#nodeCreate']);
// Page from which to edit nodes
Route::get('projects/{project}/nodes/{node}/edit',
['uses' => 'NodeController#nodeEditShow']);
// Update an existing node through put method
Route::put('projects/{project}/nodes/{node}',
['uses' => 'NodeController#nodeEdit']);
// Page from which a node deletion is confirmed
Route::get('projects/{project}/nodes/{node}/delete',['uses' => 'NodeController#nodeDeleteShow']);
// Delete node
Route::delete('projects/{project}/nodes/{node}', ['uses' => 'NodeController#nodeDelete']);
// Page from which a user is selected to be added to a node
Route::get('/projects/{project}/nodes/{node}/members/add',
['uses' => 'NodeController#nodeAddMember']);
// Add existing project member user to specific project node
Route::post('/projects/{project}/nodes/{node}/members/add',
['uses' => 'NodeController#nodeAddExistingMember']);
// Page to confirm node member removal
Route::get('/projects/{project}/nodes/{node}/members/{user}/remove',
['uses' => 'NodeController#nodeRemoveMemberShow']);
// Remove node member user from a specific project node
Route::post('/projects/{project}/nodes/{node}/members/{user}/remove',
['uses' => 'NodeController#nodeRemoveMember']);
/* =========================================================================
* Task specific routes
*/
// Page from which to view task
Route::get('projects/{project}/nodes/{node}/tasks/{task}',
['uses' => 'TaskController#show']);
// Page from which to create new task
// return 'dashboard' is a test.
Route::get('/projects/{project}/nodes/{node}/tasks/create', function(){
return 'dashboard';
});
/*Route::get('/projects/{project}/nodes/{node}/tasks/create',
['uses' => 'TaskController#taskCreateShow']);*/
// Create a new task through post method
Route::post('/projects/{project}/nodes/{node}/tasks',
['uses' => 'TaskController#taskCreate']);
// Page from which a task deletion is confirmed
Route::get('projects/{project}/nodes/{node}/tasks/{task}/delete',
['uses' => 'TaskController#taskDeleteShow']);
// Delete task
Route::delete('projects/{project}/nodes/{node}/tasks/{task}',
['uses' => 'TaskController#taskDelete']);
/* =========================================================================
* Io specific routes
*/
// Page from which to create new io
Route::get('/projects/{project}/nodes/{node}/tasks/{task}/ios/create',
['uses' => 'IoController#ioCreateShow']);
// Create a new io through post method
Route::post('/projects/{project}/nodes/{node}/tasks/{task}/ios/',
['uses' => 'IoController#ioCreate']);
// Page from which an io deletion is confirmed
Route::get('projects/{project}/ios/{io}/delete',
['uses' => 'IoController#ioDeleteShow']);
// Delete io
Route::delete('projects/{project}/ios/{io}',
['uses' => 'IoController#ioDelete']);
/* =========================================================================
* User authentication controllers
*/
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
/* =========================================================================
* Community
*/
Route::get('/community', ['uses' => 'UserController#community']);
/* Testing routes
*
* =========================================================================
*
*/
// Page from which to test project
Route::get('projects/{project}/test', ['uses' => 'ProjectController#test']);
Thanks guys, I missed a route that was indeed taking precedence as mentioned in the comments. I changed the route from:
Route::get('projects/{project}/nodes/{node}/tasks/{task}',
['uses' => 'TaskController#show']);
to:
Route::get('projects/{project}/nodes/{node}/tasks/{task}',
['uses' => 'TaskController#show'])
->where('project','[0-9]+')
->where('node','[0-9]+')
->where('task','[0-9]+');
All is working well again. I'll perhaps change some of the other routes also to make them more robust.

All routes throw NotFoundHttpException but home

I got this code in the routes.php:
Route::get('/', array('as' => 'home', function()
{
return View::make('list.open');
}));
Route::get('room/{name}', array('as' => 'showRoom', 'uses' => 'RoomController#showRoom'));
Route::post('room', array('as' => 'openRoom', 'uses' => 'RoomController#openRoom'));
And this code in the RoomController.php:
class RoomController extends Controller {
public function openRoom()
{
return "test";
}
public function showRoom($name)
{
return "test2";
}
}
If I open public/ it will Show me the view list.open but if I open public/room/test it throw the NotFoundHttpException. (I also tried to use directly a function in the routes.php instead of the roomcontroller but it doesnt worked)
Can anyone help me?
Kind regards
Damon
You don't need to add the public folder to your path, you can just go to http://location.com/room/test.
I just reinstalled a new larapack and deleted the old one... I've to start from Zero but now it works.

Categories