Views live in resources/views and end in .blade.php. view('lessons.index') loads resources/views/lessons/index.blade.php.
<?php
// In a controller method
return view('lessons.index', [
'lessons' => ['Routes', 'Blade', 'Eloquent'],
]);Blade syntax
{{ $name }}prints a value and escapes HTML, so text from users can't inject scripts.@if,@elseand@endifshow parts of the page only when a condition is true.@foreach ($lessons as $lesson)...@endforeachrepeats HTML for each item.@extends('layouts.app')reuses a layout; the page fills its@yield('content')with@section('content').
Code examples
{{-- resources/views/lessons/index.blade.php --}}
<h1>Lessons</h1>
@if (count($lessons) === 0)
<p>No lessons yet.</p>
@else
<ul>
@foreach ($lessons as $lesson)
<li>{{ $lesson }}</li>
@endforeach
</ul>
@endifExpected output
A "Lessons" heading followed by a bulleted list: Routes, Blade, Eloquent.
{{-- --}} is a Blade comment: it is not sent to the browser.
Common mistakes
Common mistake: Using {!! !!} to print what users typed
{!! !!} prints raw HTML, so a user could inject a script. Use {{ }}, which escapes it.
Common mistake: “Undefined variable $lessons”
The view only sees what you pass in. Check the array key in view('...', ['lessons' => ...]) matches the variable name.
Check your understanding
3 quick questions about this lesson.