Laravel routing without appending any prefix - php

I have a path in Laravel it is like subdomain.mydomain.com/admin/login
I am trying to call
subdomain.mydomain.com and need to get the login page straight.
Currently, it's not working
This is the function I am using in routerserviceprovider.php
protected function mapAdminRoutes()
{
Route::middleware('subdomain.mydomain.com')
->prefix('admin')
->namespace($this->namespace)
->group(base_path('routes/admin.php'));
}
and in admin.php there is a resource group shows like this:
Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function() {
//Login Routes...
Route::view('login','admin.login');
});
can anyone help with this?

Add following route
Route::get('/',function(){ return view('login.index'); })->name('admin.login');
i hope it helps

Related

fetching route from vendor through routes/web.php

I have this route included in my web.php in my routes folder.
Route::group(['prefix' => 'admin','namespace'=>'Admin', 'middleware' => 'admin', 'as' => 'admin.'], function () {
Route::group(['prefix' => 'filemanager'], function () {
\UniSharp\LaravelFilemanager\Lfm::routes();
});
});
My issue is whenever I run php artisan route:list I get the following error:
Class App\Http\Controllers\Admin\UniSharp\LaravelFilemanager\Controllers\LfmController does not exist
The Lfm controller is inside my vendor folder and I've been scouting around the internet for a solution and applied many different ways for the route change and the only way I got it to work is by using the route provided by default from the package. But if I use that, I use lose my admin authentication I'm hoping someone could give me some insight as to what I'm doing wrong here?
I would really appreciate that! Thank you in advance.
I came up with this solution. I am using Laravel 5.4
Instead of putting the code in routes/web.php, put it in RouteServiceProvider, so the default namespace is not set yet;
protected function mapWebRoutes()
{
Route::group(['prefix' => 'laravel-filemanager', 'middleware' => ['web', 'auth']], function () {
\UniSharp\LaravelFilemanager\Lfm::routes();
});
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/web.php');
});
}
For laravel 5.6 and above,
Go to config/lfm.php and set 'use_package_routes' to false.
In routes/web.php use the following routes (this is an example, might change adhering to your prefix etc.):
Route::group(['prefix' => 'admin','namespace'=>'Admin', 'middleware' => 'admin', 'as' => 'admin.'], function () {
Route::get('/filemanager', '\UniSharp\LaravelFilemanager\Controllers\LfmController#show')->name('show');
Route::any('/filemanager/upload', '\UniSharp\LaravelFilemanager\Controllers\UploadController#upload')->name('unisharp.lfm.upload');
Route::get('/filemanager/errors', '\UniSharp\LaravelFilemanager\Controllers\LfmController#getErrors')->name('getErrors');
Route::get('/filemanager/jsonitems', '\UniSharp\LaravelFilemanager\Controllers\ItemsController#getItems')->name('getItems');
Route::get('/filemanager/move', '\UniSharp\LaravelFilemanager\Controllers\ItemsController#move')->name('move');
Route::get('/filemanager/domove', '\UniSharp\LaravelFilemanager\Controllers\ItemsController#move')->name('domove');
Route::get('/filemanager/newfolder', '\UniSharp\LaravelFilemanager\Controllers\FolderController#getAddfolder')->name('getAddfolder');
Route::get('/filemanager/folders', '\UniSharp\LaravelFilemanager\Controllers\FolderController#getFolders')->name('getFolders');
Route::get('/filemanager/crop', '\UniSharp\LaravelFilemanager\Controllers\CropController#getCrop')->name('getCrop');
Route::get('/filemanager/cropimage', '\UniSharp\LaravelFilemanager\Controllers\CropController#getCropimage')->name('getCropimage');
Route::get('/filemanager/cropnewimage', '\UniSharp\LaravelFilemanager\Controllers\CropController#getNewCropimage')->name('getCropimage');
Route::get('/filemanager/rename', '\UniSharp\LaravelFilemanager\Controllers\RenameController#getRename')->name('getRename');
Route::get('/filemanager/resize', '\UniSharp\LaravelFilemanager\Controllers\ResizeController#getResize')->name('getResize');
Route::get('/filemanager/doresize', '\UniSharp\LaravelFilemanager\Controllers\ResizeController#performResize')->name('performResize');
Route::get('/filemanager/download', '\UniSharp\LaravelFilemanager\Controllers\DownloadController#getDownload')->name('getDownload');
Route::get('/filemanager/delete', '\UniSharp\LaravelFilemanager\Controllers\DeleteController#getDelete')->name('getDelete');
Route::get('/filemanager/demo', '\UniSharp\LaravelFilemanager\Controllers\DemoController#index')->name('getDelete');
});

Laravel 5.6 get user in Routes issue

How to get an id of the user?
app/routes/web.php
Route::group(['middleware' => 'auth'], function()
{
var_dump(Auth::user());
}
It returns null.
Simple things made difficult.. Also there is no reliable explanation
How to handle this?
You have not defined any route, try this instead:
Route::group(['middleware' => 'auth'], function () {
Route::get('/', function () {
dd(Auth::user());
});
});
Change the '/' to what ever you like, does that work for you?

How to Map new route to specific old route in Laravel?

I have following route group for admin panel
Route::prefix('admin')->group(function (){
.
.
.}
I want to wrap this route to a new route e.g asda12asda
so that old behavior :
/admin/users
is changed to :
/asda12asda/users
not allowing old route. I don't want to change it internally from the system and want to find some efficient Laravel way to achieve it.
Redirect the old route to a new route
Route::prefix('admin')->group(function (){
Route::any('login', function () {
// Redirect to new route
redirect()->route('new route');
});
});
by creating a new route and mapping it accordingly
Route::prefix('asda12asda')->group(function () {
Route::any('login', function () {
// Do whatever you were about to do
})->name('new route');
});
If you are using Laravel 5.4 then you can add a new route file. Assume your route name is
adsp.php then add it to RouteServiceProvider.php like this.
protected function mapApiRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/adsp.php.php');
});
}

Laravel: how to use /admin

I want to create pages for admin and I want to use dashboard in localhost:8000/admin url...but the page is showing a display Not Found Error.
Please tell me what should I do to resolve this
You need somethig like this in your /app/Http/routes.php
Route::group(['prefix' =>'admin', 'namespace' => 'admin', 'middleware' => 'auth'], function() {
Route::get('/', 'AdminController#index');
// .....
});

Laravel auth check for all pages

I have created the Authentication, and its working perfectly. But there is some problem in checking the inner pages. For example,
Route::get('/', array('before' => 'auth' , 'do'=> function(){
return View::make('home.index');
}));
The index page is only visible for logged in users. But whenever I have go to the inner pages, for example example.com/products. The products page can be visible without log in.
Here is my solution.
/**
* Groups of routes that needs authentication to access.
*/
Route::group(array('before' => 'auth'), function()
{
Route::get('user/logout', array(
'uses' => 'UserController#doLogout',
));
Route::get('/', function() {
return Redirect::to('dashboard');
});
Route::get('dashboard', array(
'uses' => 'DashboardController#showIndex',
));
// More Routes
});
// Here Routes that don't need Auth.
There are several ways of applying filters for many routes.
Putting rotues into Route::group() or if you using controllers add the filter there, add it in the Base_Controller so it will be applied to all. You can also use filter patterns and use a regex which applies the filter to all except a few you don't want to.
Documentation
Route filters: http://laravel.com/docs/routing#route-filters
Example to the pattern filter, as the others are basicly in the docs. This one could be the fastest but also the most problematic because of the problematic way of registering a regex in this function (the * is actually converted into (.*)).
Route::filter('pattern: ^(?!login)*', 'auth');
This will apply auth to any route except example.com/login.
Route::group(['middleware' => ['auth']], function()
{
Route::get('list', 'EventsController#index');
});
Read more on the documentation page:
https://laravel.com/docs/5.2/routing#route-groups
There may be a better way but I take a whitelist approach. Everything is blocked from public except for what the pages I put in this array.
// config/application.php
return array(
'safe' => array(
'/',
'card/form_confirm',
'record/form_create',
'card/form_viewer',
'user/login',
'user/quick_login',
'user/register',
'info/how_it_works',
'info/pricing',
'info/faq',
'info/our_story',
'invite/accept',
'user/terms',
'user/privacy',
'email/send_email_queue',
'user/manual_login',
'checkin/',
'checkin/activate',
'system/list',
),
// routes.php
Route::filter('before', function()
{
// Maintenance mode
if(0) return Response::error( '503' );
/*
Secures parts of the application
from public viewing.
*/
$location = URI::segment(1) . '/' . URI::segment(2);
if(Auth::guest() && !in_array( $location, Config::get('application.safe')))
return Redirect::to( 'user/login' );
});
this code working fine with me
Auth::routes();
Route::group(['middleware' => 'auth'], function () {
// Authentication Routes...
Route::get('/', 'HomeController#index')->name('home');
});
The same problem can be solved using a BaseController to extends all Controller have must logged user.
Example:
class SomeController extends BaseController
{
public function index() { return view('some.index');}
}
just add a __construct() method to BaseController
class BaseController extends Controller
{
protected $redirectTo = '/myIndex'; // Redirect after successfull login
public function __construct()
{
$this->middleware('auth'); // force all controllers extending this to pass auth
}
}
More info here
Just check if user is logged in in your views.
Or restrict all controller (if you use it)
Or check Route Groups, and give a filter to whole group of routes: http://laravel.com/docs/routing#groups
Route::filter('pattern: /*', array('name' => 'auth', function()
{
return View::make('home.index');
}));
It worked for me . take a look at it.
Route::when('*', 'auth.basic');
Route::get('api/getactorinfo/{actorname}', array('uses' =>'ActorController#getActorInfo'));
Route::get('api/getmovieinfo/{moviename}', array('uses' =>'MovieController#getMovieInfo'));
Route::put('api/addactor/{actorname}', array('uses' =>'ActorController#putActor'));
Route::put('api/addmovie/{moviename}/{movieyear}', array('uses' =>'MovieController#putMovie'));
Route::delete('api/deleteactor/{id}', array('uses' =>'ActorController#deleteActor'));
Route::delete('api/deletemovie/{id}', array('uses' =>'MovieController#deleteMovie'));

Categories