Topics Laravel Basics Blade Basics & Configuration
beginner 14 min read

Blade Basics & Configuration

Blade templating engine fundamentals, configuration files, environment variables, and service providers.

Blade Templating

Blade is Laravel's templating engine. Files use the .blade.php extension.


<html>
<head>
<title>@yield("title")</title>
</head>
<body>
@yield("content")
</body>
</html>


@extends("layouts.app")

@section("title", "Home Page")

@section("content")
<h1>Welcome</h1>
<p>{{ $message }}</p>
@endsection

Blade Syntax

{{ $name }} // Escaped output
{!! $html !!} // Unescaped output (use sparingly)
@{{ $vueVariable }} // JavaScript framework binding

@if (count($items) > 0)
<p>Items found: {{ count($items) }}</p>
@else
<p>No items.</p>
@endif

@foreach ($users as $user)
<p>{{ $user->name }}</p>
@endforeach

Configuration

// config/app.php
return [
"name" => env("APP_NAME", "Laravel"),
"env" => env("APP_ENV", "production"),
"debug" => (bool) env("APP_DEBUG", false),
"url" => env("APP_URL", "http://localhost"),
];

// Access config
$appName = config("app.name");
$timezone = config("app.timezone");

Laravel 13: Config Improvements

Laravel 13 introduces config:show for inspecting config values from the CLI. Environment files support .env.encrypted out of the box.

Examples

<?php
// resources/views/greet.blade.php
// <h1>Hello, {{ \$name }}!</h1>
// <p>Today is {{ now()->format('l, F jS') }}.</p>

// In controller:
// return view('greet', ['name' => 'Alice']);

echo view('greet', ['name' => 'Alice'])->render();

Your Notes

Sign in to take notes for this lesson.

Discussion

Sign in to join the discussion.

Flashcards

Sign in to create flashcards.