Download the HTML file directly from the public folder as a view in Laravel

I am using Laravel. I'm trying to put together my own wedding invitation. I have a folder in my shared folder, styles and scripts.

I am wondering if I can point to this folder and not copy and paste everything into a new click file.


Route

Route::get('/wedding', ' WeddingController@index ');


Weddingcontroller

 <?php namespace App\Http\Controllers; class WeddingController extends Controller { public function index() { return view('wedding.index'); } } 

Question

I am wondering if I can specify an index function to load index.html from one of my folders into the / public folder.

Do I need to download the .blade file from the app/resources/views directory?

Any recommendations / suggestions on this subject would be highly appreciated.

+4
source share
3 answers

Just put the wedding folder right in the shared folder:

 mv wedding/ /path/to/laravel/public 

Then visit the URL of your site with the suffix for the wedding:

 http://my-site.com/wedding 

This will load index.html from the wedding folder.

This works with the Nginx try_files directive in the /etc/nginx/sites-enabled/my-site configuration file:

 location / { try_files $uri $uri/ /index.php?$query_string; } 

This instructs Nginx to first search for the actual file matching the URL (e.g. /css/app.css , /wedding/index.html , etc.). If it does not find the corresponding file (for example, it usually returns 404 not found), it should instead pass the query string as an argument to the index.PHP script.

+3
source

Downloading static files from a controller using File Facade

 use File; return File::get(public_path() . '/to new folder name/index.html'); 
+2
source

One solution is to rename your wedding invitation index.html to index.php and place it in your resources/views folder so that it becomes a Laravel template.

 cd path/to/laravel mkdir resources/views/wedding mv public/wedding/index.html resources/views/wedding/index.php 

Then you can call it from your controller as you wish:

 public function index() { return view('wedding.index'); } 

Of course, with this method you will need to make sure that the CSS / JavaScript / image URLs are correctly mapped to the corresponding places in the public/ folder.

+1
source

All Articles