I would like to ask if it's possible to attache child routes to they're parent route?
If all routes are defined on the main route then I can use the route object to build my 2-level menus.
I also just want to set-up all routes in one file.
All the route configuration will be present in the navigation model which you can access using router.navigationModel. Even though you configure your router inside a parent viewmodel, the child routers will still be present inside the navigation model.
Related
I would like to have different login view for different subdomain.
My system has 2 modules for login.
-Member: www.example.com
-Agent: agent.example.com
I would like to implement 2 different login layout also different flow but using same users table.
-Member: www.example.com/login
-Agent: agent.example.com/login
inside my routes/web.php
Route::domain('agent.example.com')->group(function () {
Route::get('/login', 'AgentController#showLoginForm')->name('agent.login');
});
However, it still show my member login screen.
But if I changed to
Route::domain('agent.example.com')->group(function () {
Route::get('/agent-login', 'AgentController#showLoginForm')->name('agent.login');
});
It display the correct controller and view.
I already added the Route::domain to filter up. But how come Laravel still pick up the original login route?
How do I separated it? I prefer to have agent.example.com/login instead of agent.example.com/agent-login
It is because I am using acacha/adminlte-laravel packages. It has the login route included in the package.
Laravel route is organized based on priority of matching. So you want your route match first, you have to put in on the top.
And due to acacha/adminlte-laravelset the Auth::route inside the package. So I can't manually set the route priority in web.php.
What you have to do is remove the Auth::route in vendor. Fork your own repo. and do the customization.
I have 2 Laravel packages; one for managing an admin panel. And the second one for filling it with useful pages.
Now the first package; let's call it AdminPackage from now on. Has a built in Menu Manager which allows me to register new headers & menu links from outside of the package.
The idea is that in my second package, which adds functionality to the first, can call the AdminPackage::menu()->addHeader() and the AdminPackage::menu()->addLink() methods to add some links to the navigation of the admin panel.
But now comes the problem:
When I call the method in my 2nd package's Service Provider I get the following error:
InvalidArgumentException
Route [route-name] not defined.
I have also tried putting the code directly in the Service I'm binding to the IoC container within my ServiceProvider. But same problem.
I get the error using it in both the boot() and register() method. So the routes have not been fully loaded at this point in time.
How can I solve this problem? I need to wait for the routes to finish loading and call the menu manager methods before the page is rendered and the menu items are displayed.
Thanks in advance!
I decided to try HMVC pattern with codeigniter but I have some doubts about how to think about and build my website structure using this pattern so I have some questions:
if the main focus is on modules what is the purpose of application/controllers, application/views and application/models.
can I remove the aboved folders and route the default controller to some module?
if I have 3 controller each of them haveing unique $type and $id but all of them need to call a controller that control every thing about comments in website and just pass $type and $id, will this confilct with HMVC pattern?
the purpose of this 3 folders is to have the most 'generic' things on your application. For example, if you have a crud model, you should have on the main model folder, outside your modules. Other example, if you have a generic header/footer view you should have it in the main views folder, and so on.
You shouldn't remove this folders, but you can set the default controller just adding the module in front.
I think this is not a problem, it will not be any conflict on hvmc pattern
here you have a good guide
I want to create a setup where I can load views from a view folder based on the first part of the REQUEST_URI.
domain/folder1/ to load views from views/folder1 folder
domain/folder2/ to load views from views/folder2 folder
How would i set it up for it to work automatically? Can i modify the view path at a certain part of the lifecycle?
Thats not how you should do it. The router shouldnt call the view directly (nor the user in your case). Create a controller and asign the views with its data there.
I have a subsite within my main site for site Administration. The site is physically stored in the form
~/Views/Administration/ViewName/Index
With controllers inside
~/Controllers/Admin/ControllerName
I am getting an exception trying to visit the page.
The view 'index' or its master was not found or no view engine
supports the searched locations. The following locations were
searched: ~/Views/ViewName/index.aspx ~/Views/ViewName/index.ascx
~/Views/Shared/index.aspx ~/Views/Shared/index.ascx
~/Views/ViewName/index.cshtml ~/Views/ViewName/index.vbhtml
~/Views/Shared/index.cshtml ~/Views/Shared/index.vbhtml
I added a route
routes.MapRoute(
"Administration", // Route name
"Administration/{controller}/{action}/{id}", // URL with parameters
new { controller = "Administration", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Going directly to the page manually
http://localhost:999/Administration/BaseItem/index
Does not result in exception, but I get no content. This leads me to believe it is not finding the View. What am I doing wrong?
I think the issue is that I have told the route engine how to route to the Controller, but I have not told the system how to route to the View. Where do I tell the system where the views are?
The problem is not with the routes, but with the design. The view engine cannot find your view, because it cannot find the correct path, since the default view engines are not designed to search for a subsite.
Instead of creating a subsite, make Administration an Area in your project. In AdministrationAreaRegistration.cs, you will set a route similar to the route you added. Place your views in the Views folder inside the Administration folder (inside the Area folder), and everything will work properly.