0% found this document useful (0 votes)
6 views14 pages

Lecture 3 Layout Template

Uploaded by

Mobarok Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views14 pages

Lecture 3 Layout Template

Uploaded by

Mobarok Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Laravel Blade Template

Layouts
Course Code: CSC 4182 Course Title: Advanced Programming In Web Technologies

Dept. of Computer Science


Faculty of Science and Technology

Lecture No: 18 Week No: 11 Semester: Summer 2020-2021


Lecturer: MD.AL-AMIN; [email protected]
Lecture Outline

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

<div class="container"> @section('content')


@yield('content') <p>This is my body content.</p>
</div> @endsection
</body>
</html>

Master Layout stored in Child Layout


resources/views/layouts
Named as app.blade.php

The content of child


layout will be placed
here
Converting Html Template In
Laravel App
Topic sub heading..

• Now we will apply the blade templates feature to our project.


• We will add header and footer for all pages in our project.
• Create a new folder in resources/views named as layouts.
• Create a file named app.blade.php in it.
• Define the structure of our pages in app.blade.php
<html>
<head></head>
<body>
<div> While defining
<h1>Welcome to Demo Laravel</h1> section we need
</div> to give this
<div> name
@yield('content')
</div>
<div>
<h3>Advanced Programming in WT</h3>
</div>
</body>
</html>
Converting HTML template The name we gave
• In our registration page modify as below. in master layout
Extending Layout
Defining Section
to yield
Converting HTML template The name we gave
• In our allcourses page modify as below. in master layout
Extending Layout
Defining Section
to yield
Output
File Upload
Topic sub heading..

• 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

 PHP Advanced and Object-Oriented Programming, 3rd Edition; Larry


Ullman; Peachpit, Press, 2013
 PHP Objects, Patterns and Practice, 5th Edition; Matt Zandstra; Apress,
2016
 Learning PHP, MySQL, JavaScript and CSS, 2nd Edition; Robin Nixon;
O’Reilly, 2009
 Eloquent JavaScript: A Modern Introduction to Programming; Marijn
Haverbeke; 2011
 Learning Node.js: A Hands On Guide to Building Web Applications in
JavaScript; Marc Wandschneider; Addison-Wesley, 2013
 Beginning Node.js; Basarat Ali Syed; Apress, 2014
References
1. https://laravel.com/docs/7.x/blade
2. https://laravel.com/docs/7.x/filesystem
3. https://laravel.com/docs/7.x/filesystem#file-uploads
Thank You!

You might also like