I have base domain routes and subdomain routes. For example if I request subdomain.example.com/test it will return me right answer. But if I want to request subdomain.example.com it will execute code from root domain.
Route::get('/', function() {
// Main
});
Route::get('/path', function() {
// ..
});
Route::group(['domain' => 'subdomain.example.com'], function()
{
Route::get('/', function() {
// How to request this part?
});
Route::get('/test', function() {
// Works
});
}
Changing the order will help - Laravel keeps the routes in order, and checks them one-by-one, so by moving the subdomain's routes above the main routes they'll get found first and used, with the global routes as fallbacks for other domains.
Route::group(['domain' => 'subdomain.example.com'], function()
{
Route::get('/', function() {
// How to request this part?
});
Route::get('/test', function() {
// Works
});
}
Route::get('/', function() {
// Main
});
Route::get('/path', function() {
// ..
});
Related
I have my own Laravel gates defined "isAdmin" and "isManager". The "auth" middleware simply means the user is logged in. My routes look like this (greatly simplified):
Route::middleware(['auth', 'can:isAdmin'])->group(
function () {
Route::get('/', function() { return response("Admin home"); });
}
);
Route::middleware(['auth', 'can:isManager'])->group(
function () {
Route::get('/', function() { return response("Manager home"); });
}
);
But what do I do for a route for a logged-in user who is neither an admin nor a manager? I would like to do this:
Route::middleware(['auth', 'cannot:isManager', 'cannot:isAdmin'])->group(
function () {
Route::get('/', function() { return response("Who are you, anyway?"); });
}
);
Anybody have any ideas? Thanks.
you can set new rule (gate) as notAdminAndManager in app/Providers/AuthServiceProvider.php on boot method
here is some example
Gate::define('isNotAdminAndManager', function (User $user) {
return (! in_array($);
});
when I go on my server, if the url is empty nothing is displayed ...
However I tested a lot of things with my roads and it works perfectly locally.
Route::get('/', function () {
return view('welcome');
});
Route::get('/', function () {
return redirect('/welcome');
});
Route::get('/', function () { return redirect()->route('home', substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)); });
Route::group(['prefix' => '{language}'], function () {
Route::get('home', 'HomeController#index')->name('home');
});
Here is the simple routing code: (i take it from official site just for example)
Route::group(['middleware' => 'auth'], function () {
Route::get('/', function () {
});
Route::get('user/profile', function () {
});
});
Is it possible to get all routes from this group programmatically? Thank you.
Hope, this function will help you..
In Routes.php file --
Route::get('routes', function() {
\Artisan::call('route:list');
echo '<pre>'; print_r(\Artisan::output());
});
i tried to configure laravel for apache2.
But if I open http://localhost/ it redirect me to http://localhost/login and there is nothing to display.
If I try http://localhost/index.php/login I get the view blade to login. But how can I remove the /index.php/
The Apache vHost config
And the "main" route
Route::get('/home', function() {
return Redirect::to('login');
});
Route::group([], function() {
Route::get('/', function() {
return Redirect::to('dashboard');
Route::get('galleries', 'GalleryController#getGalleries');
Route::get('galleries/{GID}', 'GalleryController#getPicuteGallery');
Route::get('news', 'NewsController#index');
Route::get('dashboard', 'DashboardController#index');
Route::get('search', 'Search\SearchController#index');
Route::get('calendar', 'CalendarController#index');
Route::get('symposium', 'SymposiumController#index');
Route::get('conference', 'ConferenceController#index');
Route::get('publication', function() {
return view('publication');
});
});
The Auth routes are predefined by AdminLTE installer.
/**
* Define the AdminLTETemplate routes.
*/
protected function defineRoutes()
{
if (!$this->app->routesAreCached()) {
$router = app('router');
$router->group(['namespace' => $this->getAppNamespace().'Http\Controllers'], function () {
require __DIR__.'/../Http/routes.php';
});
}
}
And the AdminLTE Router
<?php
/*
* Same configuration as Laravel 5.2:
* See https://github.com/laravel/framework/blob/5.2/src/Illuminate /Auth/Console/stubs/make/routes.stub
*/
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/home', 'HomeController#index');
Route::get('/', function () {
return view('welcome');
});
});
---UPDATE---
I found out that the mod_rewrite wasnt enabled. Now the web site works fine.
But I need to add the 'middleware' => 'web' class
Remove ['middleware' => 'web'] from you routes.php, because since Laravel 5.2.27 this middleware applies automatically to all your routes and if you're adding it manually, it may give you broken app.
UPDATE:
You have a function which redirects you to 'dashboard' (why?) and also the function is not closed. So try to remove these lines:
Route::get('/', function() {
return Redirect::to('dashboard');
I use group to help visualize my project's routes.php, now the problem is
for example, when a user access to "/dir", I want to make it be redirected to "/dir/ele"
Route::group(['prefix' => 'dir'], function () {
Route::group(['prefix' => 'ele'], function () {
Route::controller('/', 'dir\eleController');
});
Redirect::route('ele');
}
Why is this not working?
The route dir/ele is going to a controller, but you are doing the redirect in your routes.php instead of in the controller.
You should use a closure route and do everything in the routes.php or use a controller and move the redirect to the controller:
Closure route in routes.php:
Route::group(['prefix' => 'dir'], function () {
Route::group(['prefix' => 'ele'], function () {
Route::get('/', function() {
return Redirect::to('ele');
});
});
});
Which can be simplified to:
Route::group(['prefix' => 'dir'], function () {
Route::get('ele', function(){
return Redirect::to('ele');
});
});
Or use the controller way:
Routes.php
Route::group(['prefix' => 'dir'], function () {
Route::group(['prefix' => 'ele'], function () {
Route::controller('/', 'eleController#redirect');
});
}
eleController.php
class eleController extends BaseController {
function redirect() {
return Redirect::to('ele');
}
}