I am new to laravel and going on to develop a web app. It has too sections, one admin side and one user side. How do I set the controllers. In admin side the links should be mywebsite/admin and in user side the links should be mywebsite/
I am using REST controllers.
Route::controller('admin','AdminController');
Route::controller('admin/place','PlaceController');
Route::controller('admin/acadamic','PlaceController');
Someone please advice me how it can be done. Thanks.
I thing its much better to build your RESTful controllers around resources like this
Route::resource('users','UsersController');
For more info take a look here
Now in order to define your routes for the admin part you can do
Route::group(array('prefix' => 'admin'), function()
{
//this resolves to admin/users
Route::resource('users', 'UsersController');
});
Related
Sorry in advance, I know it has been asked before but I did not figure out the solution.
I am new to Laravel, still learning and stuck with this issue:
My objective is to add pages in admin and show these pages in frontend.
For the Front part of the website I have this route:
Route::get('/{page}', 'PagesController#show');
so the when you access /about, /contact, /another-page I use the same view
For the Admin part of the website I have this route:
Route::get('/admin', 'AdminController#show');
My problem is that the first route overwrites the second route and I don't know how to avoid this.
I have tried with namespaces and grouping routes, but I get the same outcome.
Thank you
To make it simple this is happening because you have the route with the parameter before the admin route so is going to send the "admin as a parameter of page"
The Simple fix is just put admin route before your "/{page} so it will find admin route first,Something Like this:
Route::get('/admin', 'AdminController#show');
Route::get('/{page}', 'PagesController#show');
But I do not recommend building your routes this way and have specifics pages setup if possible, This way of building routes will mess around with the 404 route not found aswell.
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.
Do you know how to pass the sessions and session auth of the App laravel to package, and vice versa? It does not work for me, I do not know what I'm missing. Thank you.
According to the image you have provided it looks like they have registered separate route file instead of default one.
Try wrapping the routes inside the web middleware like
Route::group([middleware' => 'web'], function() {
//Your routes here
});
Without the web middleware your session won't work.
I need structure tips before I create my personal website using Laravel 5.3.
Should I use a separate Laravel install for my subdomain backend to be safer or should I only use one Laravel install and do the routes below?
Which is the best practice and easier to maintain?
Should I use subdomain for my Backend Admin or just use sub-folder (www.domain.com/admin)
MY CURRENT STRUCTURE BELOW
Preferred URLs:
http://www.domain.com (Frontend)
http://admin.domain.com (Backend)
Controllers:
app\Http\Controllers\Admin\AdminController.php (Backend)
app\Http\Controllers\HomeController.php (Frontend)
Routes File:
Route::group(array('domain' => 'domain.com'), function() {
Route::get('/', 'HomeController#index');
});
Route::group(array('domain' => 'admin.domain.com'), function() {
Route::get('/', 'Admin\AdminController#index');
});
VHOST:
127.0.0.1 domain.com
127.0.0.1 admin.domain.com
Should I use a separate Laravel install for my subdomain backend to be
safer or should I only use one Laravel install and do the routes
below?
Separate the installation only if there exists a chance that you will move the admin to some other location later. If that is not the case better keep the everything under one installation, so that the dependencies will be same and you don't need to maintain the two configs, two models for every entity etc etc. Only thing you need to keep in mind is to structure the Admin & User routes separately with controllers in different folder which you have done already.
Which is the best practice and easier to maintain?
As explained above the easier way to maintain is to keep everything under one installation.
Should I use subdomain for my Backend Admin or just use sub-folder
That's up to you. But better the admin path a not-simply-guessable one. Something like domain.com/adm1n or adm1n.domain. com or something more complex.
I am using the great charima bundle to the laravel framework 3.2.
How can I add a login page to the /admin page?
Charisma is not an administration panel in itself. It is simply a user-interface (or theme, whichever you prefer) that you can use for your own administration panel. You will need to build your own panel that makes use of it.
Please consider looking at the Laravel Auth Usage Documentation for further information on using authentication and protecting your admin route.
Route::get('admin', array('before' => 'auth', function() {}));