Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: define the route if it is same as public folder subdirectory

Tags:

php

laravel

I have admin subfolder in the public folder, but I want to define the specific response on mywebsite.loc/admin. Currently, if to input mywebsite.loc/admin, it will be next response:

enter image description here

However I has the routes definition for admin:

Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function(){

    Route::get('/', [
        'as' => 'AdminTop',
        'uses' => //Admin\AdminController@renderTopPage'
        function(){ 
            dd('ok');
        }
    ]);       
});

How I can make it work?

like image 257
Takeshi Tokugawa YD Avatar asked Feb 10 '18 06:02

Takeshi Tokugawa YD


People also ask

How do you use GET and POST for the same route in Laravel?

Route::get('login', 'AuthController@getLogin'); Route::post('login', 'AuthController@postLogin'); So instead of having to write both you only have to write one since their both using the 'same' method but also the URL remains as site.com/login instead of a redirect to site.com/auth/login ?

Where you should define your web routes in Laravel folder?

All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by your application's App\Providers\RouteServiceProvider . The routes/web.php file defines routes that are for your web interface.

Why we use named route in Laravel?

Named routes is an important feature in the Laravel framework. It allows you to refer to the routes when generating URLs or redirects to the specific routes. In short, we can say that the naming route is the way of providing a nickname to the route.


1 Answers

If you create any folder in public and you want to use this folder as a route then you need to add your index.php which is useful for understanding this folder as a root.

For example, you create one folder in public/admin now you copy your public/index.php file into your admin folder and change two line in this index.php file

require __DIR__.'/../bootstrap/autoload.php';

TO

require __DIR__.'/../../bootstrap/autoload.php';

And

$app = require_once __DIR__.'/../bootstrap/app.php';

TO

$app = require_once __DIR__.'/../../bootstrap/app.php';

I think it helps in your requirements.

Sorry for my bad english

like image 50
bipin patel Avatar answered Sep 24 '22 17:09

bipin patel