I am struggling to understand how can someone load index.html
file with Laravel. It seems to work only with index.php which is not something I want.
Here is a problem:
I have two folders client and server. My server folder contains the entire Laravel app. My client directory contains AngularJS app. (I can't use public directory)
I want Laravel to serve index.html
along with all static files from the client directory.
Changing 'public' => __DIR__.'/../public'
did somewhat work, but then it breaks all my routes, i.e. no matter what I type for URL index.html
gets loaded with broken static assets. For example /api/users
does not return a JSON object anymore but the same index.html
.
Using your text editor, create a new file called index. html and save it just inside your test-site folder.
I am not sure what's going on with your file structure, however, to load html files through the php engine you can use:
View::addExtension('html', 'php');
Then,
Route::get('/', function()
{
return View::make('index');
});
should return index.html.
I believe I understand you now. Here's a potential solution, assuming a directory structure something along the lines of this:
/
/client
index.html
/server
/app
/bootstrap
/public
/vendor
...
Use a blade template within Laravel. Your case is pretty unique, so its not going to be a 'normal' blade template. It can look like this:
{{ file_get_contents(base_path() . '../client/index.html') }}
If you can instead use an index.php
file inside of your /client
directory it could also look like this:
<?php include base_path() . '../client/index.php'; ?>
I'm only pointing this out because you could then use other PHP statements inside of the file should you need or desire to. You could also potentially pass data from your controller all the way down and into this index.php
file with the normal View::make('angular')->with('var', $var)
and they will automatically be in scope.
This seems a little hacky, and it is, but should keep you from having to modify anything else. Of course, your index.html
file should include the entire markup for the angular application. Another benefit is that, since you're pretty much still contained completely within Laravel, you could potentially move stuff 'up' and out of your angular application and back into the framework should it not be necessary there (for whatever reason).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With