Groups in group on routing - laravel

Simple little question :
on Laravel 4, it seems that a group of routes into an another group isn't working.
Is there any solution to make it work ? Or do I have to write my routes in another way ?
Example :
Route::group(array('prefix' => 'app', 'before' => 'auth_api'), function()
{
Route::group(array('prefix' => '{app_id}'), function()
{
Route::get('/', 'AppController#show');
Route::group(array('prefix' => 'achievement'), function()
{
Route::get('/{id}', 'AchievementController#show');
});
});
});
I'm unable to get a route to (example here) app/1234/achievement/1
Maybe it's too complex here. I have not any error, just a blank page (no PHP error)

Laravel 4 isn't offering this possibility but this package : https://github.com/jasonlewis/enhanced-router do the work.

Related

How to use laravel file manager by unisharp on shared hosting

First I will tell you that I have made this on my localhost and works well. But when I use on the production server(shared hosting) it does not work.
when I access my web it shows :
Class 'UniSharp\LaravelFilemanager\Lfm' not found
I put this on my route/web.php :
Route::group(['middleware' => ['auth', 'verified']], function () {
Route::group(['prefix' => 'laravel-filemanager', 'middleware' => ['web']], function () {
\UniSharp\LaravelFilemanager\Lfm::routes();
});
});
I have run all commands from the documentation, and also upload all necessary files that produced by the commands. Thanks in advance

laravel 5.2 make dashboard for admin

I am new in laravel 5.2. I want to make dashboard for admin but i do not understand how to make it. I did copy all controller files in admin folder and also copied view folder in admin folder.
I did try some code which is mention below:-
Route::group(array('namespace'=>'Admin'), function()
{
Route::get('/admin', array('as' => 'admin', 'uses' => 'UserController#index'));
Route::get('/admin/register', array('as' => 'register', 'uses' => 'UserController#register'));
Route::get('/admin/login', array('as' => 'login', 'uses' => 'UserController#login'));
});
but now I want to show all controller files under admin like:-
localhost:8000/admin/users
If you want to use all route of admin on localhost:8000/admin.
You should use route group and add prefix on it, like that
Route::group(['prefix' => 'admin/'], function () {
Route::get('users', function () {
// Matches The "/admin/users" URL
});
Route::get('login', function () {
// Matches The "/admin/login" URL
});
.......
});
Read more at this doc https://laravel.com/docs/5.2/routing#route-groups
I hope this could help you.

Multi domain routing in Laravel 5.2

I have setup multi-domain routing in my laravel 5.2 app. What I want to achieve is if a user hits, membership.app, he should be served different homepage as compared to user who hits, erp.app domain.
Route::pattern('erp', 'erp.app|erp.domain.com');
Route::pattern('membership', 'membership.app|membership.domain.com');
Route::group(['middleware' => ['web', 'auth'], 'domain' => '{erp}'], function() {
Route::get('/', 'HomeController#getIndex');
Route::controller('members', 'MembersController');
Route::controller('users', 'UsersController');
Route::controller('settings', 'SettingsController');
});
Route::group(['middleware' => 'web', 'domain' => '{erp}'], function () {
Route::controller('auth', 'Auth\AuthController');
});
Route::group(['middleware' => 'web', 'domain' => '{membership}'], function () {
Route::controller('/', 'BecomeMemberController');
});
Route::group(['middleware' => 'web'], function () {
Route::controller('ajax', 'AjaxController');
});
I tried this setup, but it breaks the code with first param in each controller method being the url instead of intended value.
Suppose I have a method hello in members controller.
public function hello($param1, $param2)
{
....
}
If I access erp.app/members/hello/1/2 url and try to print out $param1 of controller method, it returns erp.app instead of intended 1 in this case.
Please help.
I don't know why aren't you seperating the routes to different controllers as you say the output will be quite different...
A quick example of to use that:
Route::group(['domain' => '{type}.myapp.com'], function () {
Route::get('members/hello/{id1}/{id2}', function ($type, $id1, $id2) {
// when you enter --> members.myapp.com/hello/12/45
var_dump($type); //memebers
var_dump($id1); //12
var_dump($id2); //45
});
});

Route Grouping and Namespaces

i have multiple namespaces in my application namely FrontEnd namespace and BackEnd namespace, now in my routes file i would like to know the correct way to direct each route to a namespace.
This is what i have at the moment:
Route::group(['namespace' => 'FrontEnd'], function()
{
Route::group(array('prefix' => '/api/v1/'), function()
{
});
});
Now the above works alright (at least when i tried it) but just to make sure i was doing the right thing i wanted to ask so i don't experience and problems in the future.
I would like to know if this is the correct way of going about it instead:
Route::group(array('prefix' => '/api/v1/'), function()
{
Route::group(['namespace' => 'FrontEnd'], function()
{
});
});
Or does it not matter at all whichever way i decide to go?
you can pass all your option for route group in attribute array like this
Route::group(array('middleware' => 'youemiddleware', 'prefix' => 'yourprefixes', 'namespace' => 'yournamespaces', 'domain' => 'subdomains'), function()
{
// your routes
});
I see no preference one over the other.
How about this?
Route::group(array('prefix' => '/api/v1/', 'namespace' => 'FrontEnd'), function()
{
// code goes here
});

Routing confusion in laravel 4

I'm experiencing routing confusion in laravel 4.
Route::group(['prefix' => 'myProfile', 'before' => 'auth|inGroup:Model|isMe'], function()
{
Route::get('/{username}', function(){
echo 'hello';
});
});
Route::get('/{username}', [
'as' => 'show-profile',
'uses' => 'ProfileController#index'
]);
When i write to address bar domain.app/myProfile it runs second route and runs ProfileController#index...
Thanks.
Looks like correct behaviour. To access first route you would have to type something like domain.app/myProfile/FooUser. You didn't specify / route in myProfile route group, so it cannot match it and uses second one.
Breaking down your routes:
1)
Route::get('/{username}', [
'as' => 'show-profile',
'uses' => 'ProfileController#index'
]);
Use /example URI to access the above route.
2)
Route::group(['prefix' => 'myProfile', 'before' =>'auth|inGroup:Model|isMe'], function()
{
Route::get('/{username}', function(){
echo 'hello';
});
});
Use /myProfile/example URI to access the above route.
Your application is working as expected.

Resources