My routes.php like this:
Route::get('deneme/{test}', 'TestController#index');
Route::get('send', 'MailController#index');
Route::get('elfinder/tinymce4', 'Barryvdh\Elfinder\ElfinderController#showTinyMCE4');
Route::group(['middleware' => ['auth', 'perm'], 'prefix' => 'admin'], function(){
Route::get('/', ['as' => 'admin', 'uses' => 'Admin\DashboardController#index']);
Route::resource('kategori', 'Admin\KategoriController');
Route::resource('icerik', 'Admin\ContentController');
// Property Routes
Route::resource('property', 'Admin\PropertyController');
Route::post("property/lang", ['uses' => 'Admin\PropertyController#langAdd', 'as' => 'admin.property.lang_add']);
Route::get("property/lang/{id}", ['uses' => 'Admin\PropertyController#langDelete', 'as' => 'admin.property.lang_delete']);
Route::get('users/add', 'Admin\UsersController#add');
Route::get('content/add', 'Admin\ContentController#add');
});
Route::get('admin/login',['as' => 'admin.get_login', function(){
return view("admin.login");
}]);
Route::post('admin/login', ['as' => 'admin.do_login', 'uses' => 'Auth\AuthController#postLogin']);
Route::get('admin/logout', ['as' => 'admin.logout', 'uses' => 'Auth\AuthController#getLogout']);
When I send request to site.dev/admin the browser say:
This webpage has a redirect loop
ERR_TOO_MANY_REDIRECTS
I have delete rotation and leave blank only PHP tag available but this url -site.dev/admin- return same error. I tested 2 browsers, Chrome and Firefox. I think this error stems from browser-cache and installed Opera browser -not installed before- but still get same error.
I solved this problem. Under the public folder exist a folder with name is admin. So i changed my rotation like this:
Route::group(['middleware' => ['auth', 'perm'], 'prefix' => 'adminpanel'], function(){
Route::get('/', ['as' => 'admin', 'uses' => 'Admin\DashboardController#index']);
Route::resource('kategori', 'Admin\KategoriController');
Route::resource('icerik', 'Admin\ContentController');
// Property Routes
Route::resource('property', 'Admin\PropertyController');
Route::post("property/lang", ['uses' => 'Admin\PropertyController#langAdd', 'as' => 'admin.property.lang_add']);
Route::get("property/lang/{id}", ['uses' => 'Admin\PropertyController#langDelete', 'as' => 'admin.property.lang_delete']);
Route::get('users/add', 'Admin\UsersController#add');
Route::get('content/add', 'Admin\ContentController#add');
});
And the new url rotation doesn't conflict any folder under the public folder.
Good works.
Related
I have problem with multi-auth. Postman says error:
problem:
Route [login] not defined.
I understand it doesn't know which one to route?
I try to make laravel passport api so I dont need any automatic redirections.. I try to create multi-auth.
Like Admins, Stylists, Freelancers, clients..
Every route have own login and registration and other routes..
I tryed to ungroup but this isn't good solution..
Route::group(['middleware' => ['json.response']], function () {
Route::get('/freelancer/{profile}', 'API\FreelancerController#profile'); // Guests can also see profiles..
Route::group(['prefix' => 'admin', 'namespace' => 'API', 'middleware' => 'auth:admin'], function() {
Route::post('/login', 'AdminController#login');
});
Route::group(['prefix' => 'freelancer', 'namespace' => 'API', 'middleware' => 'auth:freelancer'], function() {
Route::post('/login', 'LoginRegisterController#login');
Route::post('/register', 'LoginRegisterController#freelancerRegister');
});
Route::group(['prefix' => 'stylist', 'namespace' => 'API', 'middleware' => 'auth:stylist'], function() {
Route::post('/login', 'LoginRegisterController#login');
Route::post('/register', 'LoginRegisterController#stylistRegister');
});
Route::group(['prefix' => 'client', 'namespace' => 'API', 'middleware' => 'auth:client'], function() {
Route::post('/login', 'ClientController#login');
Route::post('/register', 'ClientController#clientRegister');
});
});
If I'm http://api.mywebsite.com/freelancer/register then I can register freelancer account..
Or If I'm http://api.mywebsite.com/admin/login then I can only login to admin dashboard.
POSSIBILITY 1
Please check what route you are targetting when creating a login request from POSTMAN.
I believe you are using a route like
http://api.mywebsite.com/login
whereas you should be using one of the following:
http://api.mywebsite.com/admin/login
http://api.mywebsite.com/freelancer/login
http://api.mywebsite.com/stylist/login
http://api.mywebsite.com/client/login
POSSIBILITY 2
If above isn't the case and you are targetting a good route then check your method, it should be POST, by default POSTMAN uses GET method when you initialize a request.
However, chances for this mistake is less as it would give rather METHOD NOT EXIST error than ROUTE NOT FOUND but it's worth a try.
I really need help!
On the Laravel 5.3, it seems that a group of routes into an another group isn't working for me. Is there any solution to make it work ? Or do I have to write my routes in another way ? This is the way I write my routes:
Route::group([
'prefix' => LaravelLocalization::setLocale(),
'middleware' => [ 'localeSessionRedirect', 'localizationRedirect' ]
],
function()
{
Route::group([
'prefix' => 'admin'
], function () {
// General Settings
Route::get('settings', [
'as' => 'admin.settings',
'uses' => 'AdminController#showSettings'
]);
});
});
I am using a prefix in the first group for the multiple language and the another group is for the admin section. I want an url like this : /en/admin/settings
The problem is solved! It did not work because I had used another route in which there was an paramater before the group of admin section ex:
Route::get('activate/{code}', [
'as' => 'auth.activation',
'uses' => 'RegistrationController#getActivate'
]);
I'm starting with laravel 5 framework and I have a problem with the routes.
In the last few days, the routes worked correctly, but today I added a new route and it doesn't work anymore.
I have these routes
Route::get('url/create', 'UrlController#create');
Route::get('url/bulk', 'UrlController#bulk_view');
Route::post('url/bulk', ['as' =>'url/bulk', 'uses' => 'UrlController#bulk']);
Route::get('url/bulk_metrics', 'UrlController#bulk_metrics_view');
Route::post('url/bulk_metrics', ['as' =>'url/bulk_metrics', 'uses' => 'UrlController#bulk_metrics']);
Route::post('url/create', ['as' =>'url/create', 'uses' => 'Urlcontroller#store']);
Route::post('url/update/{id}', ['as' =>'url/update', 'uses' => 'Urlcontroller#update']);
Route::get('urls', ['as' =>'url/list', 'uses' => 'Urlcontroller#index']);
Route::get('url/{id}', ['as' =>'url/show', 'uses' => 'Urlcontroller#show']);
Route::post('url/delete/{id}', ['as' =>'url/delete', 'uses' => 'Urlcontroller#destroy']);
All work correctly, but I added this new route
Route::post('urls/filter', ['as' =>'url/filter', 'uses' => 'Urlcontroller#filter']);
and I call it like this
{!! Form::open(array('route' => 'urls/filter', 'method' => 'POST')) !!}
I tried php artisan route:clear, php artisan route:cache and php artisan route:list, and the new route appear in the list:
POST | urls/filter | url/filter | App\Http\Controllers\Urlcontroller#filter | web,auth |
The other routes work correctly and I think that it is a cache problem, because if I change the url/create to url/create2, and I change it in the template to url/create2 it doesn't work.
Thanks in advance to all
You should use it as url/filter
{!! Form::open(array('route' => 'url/filter', 'method' => 'POST')) !!}
because you're naming it like this:
'as' =>'url/filter'
Or remove 'as' =>'url/filter' part from route. In this case name of your route will be urls/filter and not url/filter.
Currently I have a routing group to subdomains and another routing group to the main site, like this:
Route::group(array('domain' => '{subdomain}.mysite.dev'), function() {
// Subdomain routes
Route::get('/', array('as' => 'home', 'uses' => 'SubdomainController#showHome'));
});
// Main
Route::get('/', array('as' => 'home', 'uses' => 'PublicController#showHome'));
It's working fine so far for both 'mysite.dev' and for 'stuff.mysite.dev' or any other subdomain.
The problem is that it assumes 'www' (as in 'www.mysite.dev') as a subdomain and I need it to be interpreted as the main site.
Thanks to itachi response, I came up with this:
Route::pattern('subdomain', '^((?!www).)*$');
Adding this line to the top of routes.php, makes the 'subdomain' match anything except 'www'.
Final form:
Route::pattern('subdomain', '^((?!www).)*$');
Route::group(array('domain' => '{subdomain}.mysite.dev'), function() {
// Subdomain routes
Route::get('/', array('as' => 'home', 'uses' => 'SubdomainController#showHome'));
});
// Main site routes (works for mysite.dev and www.mysite.dev)
Route::get('/', array('as' => 'home', 'uses' => 'PublicController#showHome'));
Route::pattern('subdomain','dev|test|mobile'); <---- add your subdomains
Route::group(array('domain' => '{subdomain}.mysite.dev'), function() {
// Subdomain routes
Route::get('/', array('as' => 'home', 'uses' => 'SubdomainController#showHome'));
});
// Main
Route::get('/', array('as' => 'home', 'uses' => 'PublicController#showHome'));
just add the 1st line and you are done!
1) You could use .htaccess redirect www to non-www
2) check http://laravel.com/docs/routing for Regular Expression constraints, so at the end of the route you add ->where('subdomain', '!www'); ( not tested )
It seems that adding
Route::controller('acme','Acme');
inside a name spaced route group does not work and i have to take it out of the whole group
check the code below
// this code does not work, error message:
//
// --------------------
// ReflectionException
// Class Api\Controllers\V1\Api\Controllers\V1\Acme does not exist
// --------------------
//
// the error appears after adding Route::controller('acme', 'Acme'); inside the name spaced route group
Route::group(['prefix' => 'api','namespace' => 'Api\Controllers'], function()
{
Route::group(['prefix' => 'v1','namespace' => 'V1'], function()
{
Route::resource('acme', 'Acme', [ 'only' => ['index', 'show', 'store', 'update', 'destroy'] ]);
Route::controller('acme', 'Acme');
});
});
// this code is working fine after taking Route::controller('acme', 'Acme'); outside the name spaced route group
Route::group(['prefix' => 'api','namespace' => 'Api\Controllers'], function()
{
Route::group(['prefix' => 'v1','namespace' => 'V1'], function()
{
Route::resource('acme', 'Acme', [ 'only' => ['index', 'show', 'store', 'update', 'destroy'] ]);
});
});
Route::controller('acme', 'Api\Controllers\V1\Acme');
you can view the code here if you prefer it more readable
http://paste.laravel.com/1inX
is it a bug or am i missing some thing ?
Yes, this is a bug. Just reproduced it here to confirm.
And posted this issue: https://github.com/laravel/framework/issues/3084
UPDATE
It works now, Taylor just killed that bug.