When I change the file-manager.php to 'routePrefix' => 'file' or 'routePrefix' => 'admin.file' the fm-button page still sends the following request.
Request URL: http://127.0.0.1:8000/file-manager/initialize
I changed the routes.php file as follows and only the routes was modified but the requests within the routes were not modified.
Route::group(['prefix' => 'admin', 'middleware' => 'admin'], function () {
Route::group([ 'prefix' => 'file-manager', 'namespace' => 'Alexusmai\LaravelFileManager\Controllers', ], function () {...
Related
I am building a modular application in laravel. I created a User module and here is the routes:
<?php
Route::group(['middleware' => 'web', 'namespace' => 'Modules\User\Http\Controllers'], function()
{
Route::get('/', 'UserController#index');
Route::get('login', 'LoginController#showLoginForm')->name('login');
Route::post('login', 'LoginController#login');
Route::post('logout', 'LoginController#logout')->name('logout');
});
Route::group(['middleware' => 'admin', 'prefix' => 'user', 'namespace' => 'Modules\User\Http\Controllers'], function()
{
Route::get('register', 'RegisterController#showRegistrationForm')->name('register');
Route::post('register', 'RegisterController#register');
});
The route('login') statement returns the url to login page and it works well. Inside the config.php I need to access this function as follows
<?php
return [
'name' => 'User',
'menu' => [
'weight' => 1,
'item' => [
'Login' => [route('login'), 'guest'],
'Register' => [route('register'), 'guest'],
]
]
];
Inside this file the error Route [login] not defined. is reported. Why is this undefined in there?
I also tried adding the following line
namespace Modules\User\Http\Controllers;
But it still not working
thanks
I have a controller That have multiple functions with the same router so I am getting error exception.
Please Guide me for This error
Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'admin']], function()
{
Route::get('/dashboard','DashboardController#chart');
Route::get('/dashboard','DashboardController#index');
});
You can't, the solution is :
Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'admin']], function()
{
Route::get('/chart','DashboardController#chart');
Route::get('/dashboard','DashboardController#index');
});
Or you can call multiple functions on the same url, one with "get" method, and an other with "post" for example :
Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'admin']], function()
{
Route::post('/dashboard','DashboardController#chart');
Route::get('/dashboard','DashboardController#index');
});
But the Route::post() is accessible only after a form submission with method post.
I need to secure my backend section.
Right now i have i like this:
Route::get('/backend',['middleware' => 'auth', 'uses' => 'HomeController#index']);
Route::get('/backend/users',['middleware' => 'auth', 'uses' => 'HomeController#show']);
Route::get('/backend/users/create',['middleware' => 'auth', 'uses' => 'HomeController#create']);
Route::get('/backend/users/edit/{id}',['middleware' => 'auth', 'uses' => 'HomeController#edit']);
do i need to write the middleware=> auth to everyline and everysite i have in my backend?
Is it somehow possible to define that everything that has 'backend/' should be checked if auth or not?
You can use a Route Group to define middleware and a prefix (among other things). So it could be:
Route::group(['prefix' => 'backend', 'middleware' => 'auth'], function () {
Route::get('/', 'HomeController#index');
Route::get('/users', 'HomeController#show');
Route::get('/users/create', 'HomeController#create');
Route::get('/users/edit/{id}', 'HomeController#edit');
)};
I have a laravel route like below :
Route::group(['namespace' => 'Aggregate\Customer\Controller\v1_0','middleware' => 'jwt.auth', 'prefix' => 'api/v1.0/{lang}'], function () {
Route::put('customer/{id}', 'CustomerController#update_customer');
});
And i want to lang key on route 'prefix' => 'api/v1.0/{lang}' be first variable globally in all methods and in all controllers without manual added in all methods like :
See $lang
public function add_address_book($lang,$user_id,AddressBookRequest $request)
{
How can i do that?
One option is update the config var app.locale.
Route::group([
'namespace' => 'Aggregate\Customer\Controller\v1_0',
'middleware' => 'jwt.auth',
'prefix' => 'api/v1.0/{lang}'
], function () {
App::setLocale(app('request')->segment(3));
Route::put('customer/{id}', 'CustomerController#update_customer');
});
Then use
echo App::getLocale();
You can set the default locale and the fallback locale in app/config.php
Another option is to set up a singleton in the app container
Route::group([
'namespace' => 'Aggregate\Customer\Controller\v1_0',
'middleware' => 'jwt.auth',
'prefix' => 'api/v1.0/{lang}'
], function () {
app()->singleton('lang', function () {
return app('request')->segment(3);
});
Route::put('customer/{id}', 'CustomerController#update_customer');
});
Then in your controllers (or anywhere) you can use
echo app('lang');
I am trying to group all the routes for our admin section to access model resources. So far I've come with this:
Route::group(['middleware' => 'auth', 'prefix' => 'admin', 'as' => 'admin::'], function() {
Route::get('dashboard', ['as' => 'dashboard', function() {
return view('pages.dashboard');
}]);
Route::resource('user', 'UserController', ['as' => 'user']);
Route::resource('plan', 'PlanController', ['as' => 'plan']);
Route::resource('answer', 'AnswerController', ['as' => 'answer']);
Route::resource('question', 'QuestionController', ['as' => 'question']);
Route::resource('retailer', 'RetailerController', ['as' => 'retailer']);
Route::resource('restriction', 'RestrictionController', ['as' => 'restriction']);
});
I want to name these routes to access them in a much easier manner by calling their names. However it breaks and says "Route [admin::user] not defined." I want to use the route naming feature to use route('admin::user'). I am having problem with the resource routes. The dashboard one works fine - route('admin::dashboard')
I take from this post that naming resource routes should work (Laravel named route for resource controller)
Resources are given route names automatically run php artisan route:list to list the routes out:
Route::group(['middleware' => 'auth', 'prefix' => 'admin', 'as' => 'admin::'], function() {
Route::get('dashboard', ['as' => 'dashboard', function() {
return view('pages.dashboard');
}]);
Route::resource('user', 'UserController');
});
Resulting Routes
admin::dashboard
admin::admin.user.store
admin::admin.user.index
admin::admin.user.create
admin::admin.user.destroy
admin::admin.user.show
admin::admin.user.update
admin::admin.user.edit