Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load an HTML file directly from public folder as View in Laravel

I'm using Laravel. I'm trying to put together my own wedding invitation. I have a folder in my public folder, will styles, and scripts for it.

I'm wondering if I can point to that folder, instead of copy-and-paste everything into a new blade 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'm wondering if I can point my index function to load the index.html from one of my folder in my /public folder.

Do we have to load the .blade file from the app/resources/views directory ?

Any helps / suggestions on this will be much appreciated.

like image 531
code-8 Avatar asked Aug 06 '15 18:08

code-8


People also ask

How do I load a view in laravel?

Loading a view in the controller is easy. You just need to add `view('viewname')` method while returning from the controller method. `view()` is a global helper in Laravel. In this method, you just need to pass the name of the view.

How do I display HTML tags as plain text in laravel?

You can show HTML tags as plain text in HTML on a website or webpage by replacing < with &lt; or &60; and > with &gt; or &62; on each HTML tag that you want to be visible. Ordinarily, HTML tags are not visible to the reader on the browser.

Where is public folder in laravel?

The storage/app/public directory may be used to store user-generated files, such as profile avatars, that should be publicly accessible. You should create a symbolic link at public/storage which points to this directory. You may create the link using the php artisan storage:link Artisan command.


2 Answers

Just place the wedding folder directly inside the public folder:

mv wedding/ /path/to/laravel/public

Then visit your site URL with a wedding suffix:

http://my-site.com/wedding

This will load the index.html from inside the wedding folder.

This works via Nginx's try_files directive in your /etc/nginx/sites-enabled/my-site config file:

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

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

like image 66
Ben Claar Avatar answered Sep 21 '22 15:09

Ben Claar


Load static files from controller using File Facade

use File;

return File::get(public_path() . '/to new folder name/index.html');
like image 23
Ankit Jain Avatar answered Sep 19 '22 15:09

Ankit Jain