Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access specific Laravel 5 route from a directory located elsewhere

I have wordpress installed:

example.com

and laravel /public dir (which is accessed from api.example.com)

example.com/api

How do i access a laravel route say /play from example.com/play

currently i have this example.com/play/play showing the correct laravel route, but i need it to go up a level.

The setup index.php in /home/public_html/play

require __DIR__.'/../../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../laravel/bootstrap/app.php';

this correctly points to the /home/laravel for example

then the routes file is

Route::group(['prefix' => 'play'], function () {    
    Route::get('/', ['as'=>'/', 'uses'=>'Controller@play']);
});

i have added RewriteCond %{REQUEST_URI} !^/(play/.*)$ to root .htaccess so wordpress doesn't take over.

and finally this is where i am hitting the problem:

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /play/index.php [L]

</IfModule>

which is located in /home/public_html/play

So how do i show the laravel route in the /play dir? Can this be achieved with rewrite? Can i pass a parameter to laravel to tell it to start /play as the root?

like image 795
Harry Bosh Avatar asked Oct 19 '16 11:10

Harry Bosh


People also ask

What is Route match in Laravel?

Laravel route model binding provides a convenient way to automatically inject the model instances directly into your routes. For example, instead of injecting a user's ID, you can inject the entire User model instance that matches the given ID.

What is Route namespace in Laravel?

The namespace on the route, is to define where the controller is for that route in Laravel. You don't have to use ->namespace() , you can do Route::get('something', 'MyNamespace\SomeController@method'); Level 2.

Where are routes in Laravel?

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.

What is route::view in Laravel?

This is not a great big feature, but it simplifies your code and removes a couple of files. Let’s define a route with Route::view, to access contact page. with the use of Route::view, we don’t have to define the controller or a closure to render a view, you can define a URI and a path to a view file.

How do I inject a Laravel model into a route?

When injecting a model ID to a route or controller action, you will often query the database to retrieve the model that corresponds to that ID. Laravel route model binding provides a convenient way to automatically inject the model instances directly into your routes.

Where is the Laravel global middleware stack located?

Your global middleware stack is located in your application's HTTP kernel ( App\Http\Kernel ). For more information on CORS and CORS headers, please consult the MDN web documentation on CORS. When deploying your application to production, you should take advantage of Laravel's route cache.


1 Answers

When you have multiple applications that you want to access it from single domain, the best implementation is to boot different server for each application. The you can set up proxy from the main application to other applications.

You can boot apache2 server for your laravel application with setup like this

<VirtualHost 0.0.0.0:8080>
  DocumentRoot "path-to-laravel-app"

  <Directory "path-to-laravel-app">

    Options Indexes FollowSymLinks Includes ExecCGI

    AllowOverride All
    Require all granted
    Allow from all
  </Directory>
</VirtualHost>

Then set up proxy in your wordpress application .htaccess file like this

ProxyPass "/play"  "http://locahost:8080/play"
ProxyPassReverse "/play"  "http://locahost:8080/play"
like image 191
Kliment Avatar answered Oct 17 '22 09:10

Kliment