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.
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.
You can show HTML tags as plain text in HTML on a website or webpage by replacing < with < or &60; and > with > or &62; on each HTML tag that you want to be visible. Ordinarily, HTML tags are not visible to the reader on the browser.
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.
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.
Load static files from controller using File
Facade
use File;
return File::get(public_path() . '/to new folder name/index.html');
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