Lecture 3 Layout Template
Lecture 3 Layout Template
Layouts
Course Code: CSC 4182 Course Title: Advanced Programming In Web Technologies
1. Laravel Layouts
2. Converting Html Template In Laravel App
3. File Upload
Laravel Layouts
Topic sub heading..
• Two of the primary benefits of using Blade are template inheritance and
sections.
• Since most web applications maintain the same general layout across various
pages, it's convenient to define this layout as a single Blade view
• There are 2 directives @section and @yield.
• The @section directive, as the name implies, defines a section of content.
• The @yield directive is used to display the contents of a given section.
• When defining a child view, use the Blade @extends directive to specify
which layout the child view should "inherit".
• Views which extend a Blade layout may inject content into the layout's
sections using @section directives.
Example
<html>
<head> @extends('layouts.app')
<title>App Name</title>
</head> @section('sidebar')
<body> @parent
@section('sidebar')
This is the master <p>This is appended to the master
sidebar. sidebar.</p>
@show @endsection
• The public disk is intended for files that are going to be publicly accessible. By
default, the public disk uses the local driver and stores these files in
storage/app/public
• To make them accessible from the web, you should create a symbolic link
from public/storage to storage/app/public
• To create the symbolic link, you may use the storage:link Artisan command
php artisan storage:link
• The URL of this file can be created using asset helper
echo asset('storage/file.txt');
• Laravel makes it very easy to store uploaded files using the store method on
an uploaded file instance.
• The path to the file will be returned by the store method so you can store the
path, including the generated file name, in your database.
$path = $request->file('avatar')->store('avatars');
File Upload
• If you would not like a file name to be automatically assigned to your stored
file, you may use the storeAs method. which receives the path, the file name,
and the (optional) disk as its arguments.
$path = $request->file('avatar')->storeAs(
'avatars', $request->user()->id
); //avatars is the folder name and file stored as user id
• If you would like to get original name of the uploaded file, you may do so
using the getClientOriginalName method
$name = $request->file('avatar')->getClientOriginalName();
• The extension method may be used to get the file extension of the uploaded
file
$extension = $request->file('avatar')->extension();
• The delete method accepts a single filename or an array of files to remove
from the disk
Storage::delete('file.jpg');
Storage::delete(['file.jpg', 'file2.jpg']);
Example
Books