หลังจากประมวลผลได้ผลลัพธ์ที่ต้องการแล้ว แทนที่จะส่งผลออกหน้าเว็บโดยตรงจาก Controller แนะนำให้ส่งผลลัพธ์ที่ได้ไปยังส่วน View เพื่อทำหน้าที่แสดงผลออกหน้าเว็บ
ใน Laravel จะใช้ Blade ทำหน้าที่เป็น Template Engine เพื่อช่วยในการแสดงผลได้ง่ายขึ้น โดยจะมีฟังก์ชันเพื่ออำนวยความสะดวกต่อการแสดงผลออกหน้าเว็บ
ลองมาดูวิธีการใช้งาน View ของ Laravel เบื้องต้นกัน
แก้ไขเมธอด contact() ในไฟล์ PageController.php ให้ไปเรียกฟังก์ชัน view() เพื่อแสดงผล
ค่าพารามิเตอร์ของฟังก์ชัน view() คือชื่อไฟล์ view ที่จะใช้แสดงผล เช่นในที่นี้กำหนดเป็น contact
<?php
// app/Http/Controllers/PageController.php
// ...
class PageController extends Controller
{
    // ...
    public function contact()
    {
        return view('contact');
    }
}ขั้นต่อไปเป็นการสร้างไฟล์ view เก็บไว้ในโฟลเดอร์ resources/views/
รูปแบบการตั้งชื่อไฟล์โดยใช้ Blade Template คือใช้ชื่อพารามิเตอร์ที่ระบุไว้ในฟังก์ชัน view() เช่น contact ตามด้วย .blade.php เช่นในที่นี้เราเรียกฟังก์ชัน view('contact') ก็ต้องระบุชื่อไฟล์ Blade Template เป็น resources/views/contact.blade.php
ตัวอย่างไฟล์ resources/views/contact.blade.php
<html>
<body>
Contact Us from View
</body>
</html>ทดลองใช้คำสั่ง curl เพื่อทดสอบ ก็จะได้ผลลัพธ์ ที่ส่งมาจากส่วน view
$ curl http://blog.test/contact
<html>
<body>
Contact Us from View
</body>
</html>ในทำนองเดียวกัน สามารถแก้ไขเมธอด home() เพื่อส่งไปให้ส่วน view แสดงผล
แก้ไขเมธอด home() ในไฟล์ PageController.php
// app/Http/Controllers/PageController.php
// ...
class PageController extends Controller
{
    public function home()
    {
        return view('home');
    }สร้างไฟล์ resources/views/home.blade.php เพื่อแสดงผล
<html>
<body>
Hello from View
</body>
</html>ทดสอบด้วยคำสั่ง curl
$ curl http://blog.test/
<html>
<body>
Hello from View
</body>
</html>จากตัวอย่างด้านบน จะเห็นว่าเมื่อเราสร้างไฟล์ view เพิ่มขึ้นเรื่อยๆ จะมีโค้ดบางส่วนที่เป็นโครงสร้างหลัก (Layout) ของเว็บที่ซ้ำซ้อน ซึ่งเราสามารถแยกส่วนนี้ออกมาเป็นไฟล์โครงสร้างหลักได้ ในที่นี้ขอใช้ชื่อเป็น app.blade.php
ตัวอย่างไฟล์ resources/views/app.blade.php เพื่อทำหน้าที่เป็นโครงสร้างหลักของหน้าเว็บ
<html>
<body>
    @yield('content')
</body>
</html>คำอธิบาย
@yield('content') จะรอรับค่าตัวแปรที่จะแสดงผล จากไฟล์ view อื่นๆ ที่มาเรียกใช้ไฟล์โครงสร้างหลักนี้แก้ไขไฟล์ contact.blade.php เพื่อเรียกใช้ไฟล์ view ที่ทำหน้าที่เป็นโครงสร้างหลัก
@extends('app')
@section('content')
Contact Us from View
@endsectionคำอธิบาย
@extends('app') ระบุไฟล์โครงสร้างหลักที่จะใช้ ในที่นี้ระบุเป็น app ซึ่งเป็นการเรียกใช้ไฟล์ app.blade.php@section และ @endsection จะกำหนดค่าตัวแปร ในที่นี้คือ content เพื่อใช้ส่งค่าเข้าไปแสดงผลในส่วน @yield ในไฟล์โครงสร้างหลัก ทดสอบด้วยคำสั่ง curl
$ curl http://blog.test/contact
<html>
<body>
    Contact Us from View
</body>
</html>แก้ไขไฟล์ home.blade.php
@extends('app')
@section('content')
Hello from View
@endsectionทดสอบด้วยคำสั่ง curl
$ curl http://blog.test/
<html>
<body>
    Hello from View
</body>
</html>ตอนนี้ทั้ง contact และ home ใช้ไฟล์โครงสร้างหลักเดียวกันแล้ว ทีนี้ถ้าเราต้องการเพิ่มเติมการแสดงผลในส่วนของ <title> ก็สามารถแก้ไขไฟล์โครงสร้างหลัก app.blade.php แค่ไฟล์เดียว โดยเพิ่มการรับค่าตัวแปร title
ตัวอย่างการแก้ไขไฟล์ resources/views/app.blade.php
<html>
<head>
    <title>@yield('title')</title>
<head>
<body>
    @yield('content')
</body>
</html>แก้ไขไฟล์ contact.blade.php
@extends('app')
@section('title', 'Contact')
@section('content')
Contact Us from View
@endsectionทดสอบด้วยคำสั่ง curl
$ curl http://blog.test/contact
<html>
<head>
    <title>Contact</title>
</head>
<body>
    Contact Us from View
</body>
</html>สามารถแก้ไข home.blade.php ได้เหมือมกัน
resources/views/home.blade.php
@extends('app')
@section('title', 'Home')
@section('content')
Hello from View
@endsectionทดสอบด้วยคำสั่ง curl
$ curl http://blog.test/
<html>
<head>
    <title>Home</title>
</head>
<body>
    Hello from View
</body>
</html>