Views in laravel contain all the HTML required to display web pages in your browser.
Views are stored in folder
By default, when you visit laravel based web site, you will see laravel default page.
If you look at app/routes.php file, you will see
Code:
Route::get('/', function()
{
return View::make('hello');
});
That means, you are displaying view file with name "hello".
To edit the default laravel page, you need to edit hello view file. This can be found in
Code:
app/views/hello.php
How to Create a New Page
To create a new page, first thing we need to do is edit file
and add route for new page. For example, we need URL
Code:
http://127.0.0.1:8000/news
Lets edit
and add
Code:
Route::get('/news', function()
{
return View::make('hello');
});
Now if you visit,
Code:
http://127.0.0.1:8000/news
You will see default laravel page. This is because, we are returning same view file "hello". To display different content for this url, you need to change route as follows.
Displaying Different View
Edit app/routes.php file.
Find
Code:
Route::get('/news', function()
{
return View::make('hello');
});
Replace with
Code:
Route::get('/news', function()
{
return View::make('news');
});
Now we are returning a View file with name news. If you go to URL
Code:
http://127.0.0.1:8000/news
You get an error as shown below.
If you read the error, you will see the error is because
That means you need to create View file with name "news".
So create a file in app/views folder.
Code:
app/views/news.blade.php
Here is sample content of news.blade.php
Code:
$ cat app/views/news.blade.php
<h1>Latest News</h1>
<p>All latest news goes here.</p>
$
Now refresh the browser. You will see the content instead of previous view error.
Bookmarks