Completed

LARAVEL TRAINING (BEGINNER - INTERMEDIATE)

Kementerian Kesihatan Malaysia

Date
16 โ€“ 22 Nov 2021
Organised by
Favourite Trainer Sdn Bhd
Trainer
Azman Zakaria
Attendees
8

Tag : Laravel, MySQL, jQuery, Twitter Bootstrap, Coaching, Javascript

Tarikh Kursus :
  Sesi 1 :  16 - 19 November 2021
  Sesi 2 : 22 November 2021

Lokasi : Favourite Trainer Sdn Bhd, Putrajaya

Pengenalan :
Kursus ini berkonsepkan "From Zero to Hero". Peserta seharusnya telah mempunyai asas PHP yang kuat terutamanaya konsep Object Oriented. Semua peserta dianggap belum pernah berpengalaman membuat pengaturcaraan Laravel Framework. Semuanya akan bermula dari scratch.

Perisian yang akan digunakan didalam kelas ini adalah seperti berikut :-

  • Laravel Framework 8
  • Laragon Full versi 4.0
  • PHP 7.4
  • MySQL 5.7
  • jQuery 3
  • Twitter Bootstrap 4
  • Visual Studio Code
  • SQL Yog
  • Composer
  • Cmder

Dicadangkan PC yang akan digunakan ialah menggunakan Window 10 dengan RAM 8 Gb, dan kapasiti Storage yang Free sebanyak min 2 Gb

Syllabus

Introduction

Laravel is a free, open-source PHP web framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller architectural pattern. Application frameworks have grown in popularity over the past five years. There has been a tremendous shift from handwriting all code to leveraging these powerful frameworks with prebuilt components and features. Laravel joined the framework scene when there were already many players. However, the developers of Laravel used this timing to their advantage, instead of creating a framework that avoided all of the problems and mistakes previous full-stack frameworks had made and building on top of the excellent Symphony components in order to create a robust, component-based framework.

What you will learn:

This course is designed for students who already attend the PHP training. Anybody without the prerequisite may follow the class but need to expect not to fully grab the concept present in the class.
This class will covers the following core topics:
  • Installation
  • Model View Controller (MVC) methodology
  • Third party-packages
  • Blade templating engine
  • Laravel best practice
  • Workshop of rela-world application

Course Duration : 5 days

 

Module 1:  Setting Up a Laravel Development Environment

 

  • System Requirement
  • Composer
  • Local Development Environments
  • Laravel Valet
  • Laravel Homestead
  • Creating a New Laravel Project
  • Installing Laravel with the Laravel Installer Tool
  • Installing Laravel withComposer’s create-project Feature
  • Lambo: Super-Powered“Laravel New”
  • Laravel’s Directory Structure
  • The Folders
  • The Loose Files
  • Configuration
  • The .env File
  • Up and Running
  • Testing

Module 2:  Routing and Controllers

  • A Quick Introduction to MVC, the HTTP Verbs, and REST
  • What Is MVC?
  • The HTTP Verbs
  • What Is REST?
  • Route Definitions
  • Route Verbs
  • Route Handling
  • Route Parameters
  • Route Names
  • Route Groups
  • Middleware
  • Path Prefixes
  • Fallback Routes
  • Subdomain Routing
  • Namespace Prefixes
  • Name Prefixes
  • Signed Routes
  • Signing a Route
  • Modifying Routes to Allow Signed Links
  • Views
  • Returning Simple Routes Directly with Route::view()
  • Using View Composers to Share Variables with Every View
  • Controllers
  • Getting UserInput
  • Injecting Dependencies into Controllers
  • Resource Controllers
  • API Resource Controllers
  • Single Action Controllers
  • Route Model Binding
  • Implicit RouteModel Binding
  • Custom RouteModel Binding
  • Route Caching
  • Form Method Spoofing
  • HTTP Verbs in Laravel
  • HTTP Method Spoofing in HTML Forms
  • CSRF Protection
  • Redirects
  • redirect()->to()
  • redirect()->route()
  • redirect()->back()
  • Other Redirect Methods
  • redirect()->with()
  • Aborting the Request
  • Custom Responses
  • response()->make()
  • response()->json() and ->jsonp()
  • response()->download(),->streamDownload(), and ->file()
  • Testing

Module 3: Blade Templating

  • Echoing Data
  • Control Structures
  • Conditionals
  • Loops
  • Template Inheritance
  • Defining Sections with @section/@show and @yield
  • Including View Partials
  • Using Stacks
  • Using Components and Slots
  • View Composers and Service Injection
  • Binding Data to Views Using View Composers
  • Blade Service Injection
  • Custom Blade Directives
  • Parameters in Custom Blade Directives
  • Example:UsingCustom Blade Directives for a Multitenant App
  • Easier Custom Directives for “if” Statements
  • Testing

Module 4: Databases and Eloquent

  • Configuration
  • Database Connections
  • Other DatabaseConfiguration Options
  • Defining Migrations
  • Running Migrations
  • Seeding
  • Creating a Seeder
  • Model Factories
  • Query Builder
  • Basic Usage of the DB Facade
  • Raw SQL
  • Chaining with the Query Builder
  • Transactions
  • Introduction to Eloquent
  • Creating and Defining Eloquent Models
  • Retrieving Datawith Eloquent
  • Inserts and Updates with Eloquent
  • Deleting with Eloquent
  • Scopes
  • Customizing Field Interactions with Accessors, Mutators, and Attribute
  • Casting
  • Eloquent Collections
  • Eloquent Serialization
  • Eloquent Relationships
  • Child Records Updating Parent Record Timestamps
  • Eloquent Events
  • Testing

Module 5: Collecting and Handling User Data

  • Injecting aRequest Object
  • $request->all()
  • $request->except() and $request->only()
  • $request->has()
  • $request->input()
  • $request->method() and ->isMethod()
  • Array Input
  • JSON Input(and $request->json())
  • Route Data
  • From Request
  • From Route Parameters
  • Uploaded Files
  • Validation
  • validate() on the Request Object
  • Manual Validation
  • Custom Rule Objects
  • Displaying ValidationError Messages
  • Form Requests
  • Creating aForm Request
  • Using a Form Request
  • Eloquent ModelMass Assignment
  • {{ Versus {!!
  • Testing

Module 6. Artisan and Tinker

  • An Introductionto Artisan
  • Basic Artisan Commands
  • Options
  • The Grouped Commands
  • Writing Custom Artisan Commands
  • A Sample Command
  • Arguments and Options
  • Using Input
  • Prompts
  • Output
  • Writing Closure-Based Commands
  • Calling Artisan Commands in Normal Code
  • Tinker
  • Laravel Dump Server
  • Testing

Module 7. User Authentication and Authorization

  • The User Modeland Migration
  • Using the auth() Global Helper and the Auth Facade
  • The Auth Controllers
  • RegisterController
  • LoginController
  • ResetPasswordController
  • ForgotPasswordController
  • VerificationController
  • Auth::routes()
  • The Auth Scaffold
  • “Remember Me”
  • Manually Authenticating Users
  • Manually Logging Out a User
  • Invalidating Sessions on Other Devices
  • Auth Middleware
  • Email Verification
  • Blade Authentication Directives
  • Guards
  • Changing theDefault Guard
  • Using Other Guards Without Changing the Default
  • Adding aNew Guard
  • Closure Request Guards
  • Creating a Custom User Provider
  • Custom User Providers for Nonrelational Databases
  • Auth Events
  • Authorization (ACL)and Roles
  • Defining Authorization Rules
  • The Gate Facade (and Injecting Gate)
  • Resource Gates
  • The Authorize Middleware
  • Controller Authorization
  • Checking on the UserInstance
  • Blade Checks
  • Intercepting Checks
  • Policies
  • Testing
 
 
 

Module 8: Requests, Responses, and Middleware

  • Laravel’s Request Lifecycle
  • Bootstrapping the Application
  • Service Providers
  • The Request Object
  • Getting a Request Objectin Laravel
  • Getting Basic Information About a Request
  • The Response Object
  • Using and Creating Response Objects in Controllers
  • Specialized Response Types
  • Laravel and Middleware
  • An Introductionto Middleware
  • Creating Custom Middleware
  • Binding Middleware
  • Passing Parameters to Middleware
  • Trusted Proxies
  • Testing

Module 9: Storage and Retrieval

  • Local and Cloud File Managers
  • Configuring File Access
  • Using the Storage Facade
  • Adding AdditionalFlysystem Providers
  • Basic File Uploads and Manipulation
  • Simple File Downloads
  • Sessions
  • Accessing the Session
  • Methods Available on Session Instances
  • Flash Session Storage
  • Cache
  • Accessing the Cache
  • Methods Available on Cache Instances
  • Cookies
  • Cookies in Laravel
  • Accessing theCookie Tools
  • Logging
  • When and Why to Use Logs
  • Writing to the Logs
  • Log Channels
  • Full-Text Search with Laravel Scout
  • Installing Scout
  • Marking Your Modelfor Indexing
  • Searching YourIndex
  • Queues and Scout
  • Performing OperationsWithoutIndexing
  • Conditionally Indexing Models
  • Manually Triggering Indexing via Code
  • Manually Triggering Indexing via the CLI
  • Testing
  • File Storage
  • Session
  • Cache
  • Cookies
  • Log
  • Scout

Module 10: Mail and Notifications

  • Mail
  • “Classic” Mail
  • Basic “Mailable”Mail Usage
  • Mail Templates
  • Methods Availablein build()
  • Attachments andInline Images
  • Markdown Mailables
  • Rendering Mailables to the Browser
  • Queues
  • Local Development
  • Notifications
  • Defining the via() Method for Your Notifiables
  • Sending Notifications
  • Queueing Notifications
  • Out-of-the-Box Notification Types
  • Testing
  • Mail
  • Notifications
     
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Training Materials

1. Laravel Book

2. PHP Tutorial (git Lab)

3. Laravel Tot (git Lab)

4. Larapro Project (git Lab)

Trainer Profile

 Nama : Azman bin Zakaria
 Umur : 52 tahun
 Pengalaman Dalam Bidang IT : 21 Tahun
 Syarikat : Favourite Trainer Sdn Bhd
 Kelulusan :

  • Bachelor IT UiTM
  • Diploma Computer Science UiTM
  • HRDF Certified Instructor

Azman merupakan senior programmer yang passionate dalam bidang pengaturcaraan komputer dari awal mulai beliau bekerja pada tahun 2000 sehingga hari ini. Beliau mempunyai pengalaman bekerja yang luas di agensi kerajaan, swasta dan sebagai freelancer.
Antara pengaturcaraan yang selalu digunakan adalah seperti :

  • PHP (sejak tahun 2000)
  • PHP dan Laravel Framework
  • PHP dan Yii Framework
  • Coldfusion
  • Java 
  • Java dan Spring Boot Framework
  • Javascript
  • jQuery
  • Vuejs
  • Angular
  • Flutter

 

Notes

installation:
- Laragon (PHP 7.4, Apache 2.4, MySQL 5.7, Cmder, Heidi SQL, Composer, Auto Virtual Host)
- Visual Studio Code (VSC)
 - extension: PHP, Prettier, Blade, Ayu Template, PHP HTML Formatter


PHP Version
--------------------
2000 - PHP v1

2021 - PHP v8

 

PHP Revision
----------------------
- First php program : Hello World


Laravel Installation
--------------------------
composer
- dependency manager
- php library installer 

>composer create-project --prefer-dist laravel/laravel laravel_tot

-error memory limit
>php -d memory_limit=-1 c:\laragon\bin\composer\composer.phar create-project --prefer-dist laravel/laravel laravel_tot

>composer self-update
 - update version of composer program

MVC = Model, View, Controller

revision:
- install VSC
- Laragon
 - PHP 7.4
 - Apache 2.4
 - MySQL 5.7
 - cmder
 - composer
 - Heidi SQL
 - auto virtual host

1. basic PHP
 - declare var $nama
 - loop
  - while(), foreach(), for()
 - function tambah($no1, $no2, $no=0)
 - OOP
  - class dan object
  - inheritance (extends)
  
2. Laravel
 installation
 - composer
 >composer create-project --prefer-dist laravel/laravel[:version] <nama projek>
 - MVC + Route
 - routing
  Route::get('/pattern', function() {...} )
  rerturn view('nama', compact('...'));
 - controller
   - class
   - class User extends Controller
   - namespace
   - controller use model. Pengguna::all()
 - Model
   - 1 model represent 1 table
   - cth: class Pengguna extends Model
   
 - view
  - print data
  - .blade.php
  - {{ ... }} - print / echo
  - layout
  - @extends('layout.app')
  - @section('body') ..... @endsection
  - @yield('body')


Blade dan Twitter Bootstrap v5
- blade = templating engine
- https://getbootstrap.com/
- Bootstrap = CSS framework
 - alternatives: Foundation / Bulma / Material / Tailwind


Laravel suggestion: dlm tiap2 table
- created_at datetime
- updated_at datetime

Laravel prefer "convention over configuration"


- PHP Artisan
 - terminal / console
 - generate controller / model / middleware ....
 - tinker

- Session
 - global variable 
 - flash session: temp session, exist 1 lifecycle
  - set message

- Middleware
 - route -> middleware -> controller
 - log
 - authentication dan authorization

- Authentication
 - login

- Authorization
 - access level


- File Storage
 - upload
 - rename file...

        <div class="row">
          <div class="col-lg-6">
            <div class="card">
              <div class="card-body">
                <h5 class="card-title">Card title</h5>

                <p class="card-text">
                  Some quick example text to build on the card title and make up the bulk of the card's
                  content.
                </p>

                <a href="#" class="card-link">Card link</a>
                <a href="#" class="card-link">Another link</a>
              </div>
            </div>

            <div class="card card-primary card-outline">
              <div class="card-body">
                <h5 class="card-title">Card title</h5>

                <p class="card-text">
                  Some quick example text to build on the card title and make up the bulk of the card's
                  content.
                </p>
                <a href="#" class="card-link">Card link</a>
                <a href="#" class="card-link">Another link</a>
              </div>
            </div><!-- /.card -->
          </div>
          <!-- /.col-md-6 -->
          <div class="col-lg-6">
            <div class="card">
              <div class="card-header">
                <h5 class="m-0">Featured</h5>
              </div>
              <div class="card-body">
                <h6 class="card-title">Special title treatment</h6>

                <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
                <a href="#" class="btn btn-primary">Go somewhere</a>
              </div>
            </div>

            <div class="card card-primary card-outline">
              <div class="card-header">
                <h5 class="m-0">Featured</h5>
              </div>
              <div class="card-body">
                <h6 class="card-title">Special title treatment</h6>

                <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
                <a href="#" class="btn btn-primary">Go somewhere</a>
              </div>
            </div>
          </div>
          <!-- /.col-md-6 -->
        </div>
        <!-- /.row -->

 

Revision day 2:
- CRUD
 - create form
 - insert (Request $req)
  - save()
 - edit, update, re-use form
  - save()
 - delete
  - delete()

Model / Eloquent Functions
 - all()
 - find()
 - save()
 - delete()

PHP Artisan
- php artisan list
- php artisan tinker
- php artisan make:controller <nama contoller>
- php artisan make:model <nama contoller>
- php artisan make:middleware <nama contoller>
- ... up , ... down

Middleware
 - run between Route dgn controller
 - Route::middleware(['nama middleware')->group(function() ....);

Authentication
 - \Auth::attempt($credentials)
 - once berjaya, refer \Auth::user()->col_name, \Auth::logout()


Class yg pre-import oleh laravel
- rujuk /config/app.php, see section aliases

Front-end tech
 - view (V)
 - Js
 - Vuejs (Community, Evan Yu)
 - Angular (google)
 - ReactJs (Fb)
 - JSON

Back-end tech
 - laravel
 - java, springboot, yii
 - MVC


SPA - Single Page Application

Debug Bar
- google "laravel debug bar"
- barryvdh (github)
APP_DEBUG=true (show debug bar) / false = turn off

pertanyaan pn su:
- kegunaan {var}
Route::get('/user/{name}', function($name) {
  echo $name;
});

{name} = variable / data

http://../user/azman
http://../user/abu


Bootstrap Template
-wrapboostrap
-evanto market
-creative tim
- ..

adminlte - free
- starter.html (copy semua src code)

sakila db
- google "download sakila mysql"


Tinker
jika ubah class selepas enter tinker, exit dulu, then enter semula
\App\Models\Film::where('title', 'Alone')->get();
 

Model Convention
1. table plural, model singular
2. primary key is ID
3. every table ada created_at, updated_at
 

2 jenis Teknik Query
1. Eloquent / ORM / Model
 - Film::all();
2. Query Builder
 - \DB::table('film')->select('title, description')->get();

revision day 3:

- install 3rd party library
 - debug bar
 - composer require <nama library> --dev
 - register composer.json
 - Query analysis
 - debug error

Bootstrap Template
 - wrapbootstrap
 - evanto market
 - adminlte
  - starter.html
 - creative tim

crate new proj
 - >composer ....
- layout/mater.blade.php
 - dashboard
 - pagination
 - sakila DB
  - film (1000)
 - tinker
  - model :Film
  - Film::all(), Film::limit(10)->get(), Film::where(...)->get()

- Query Builder (5% - 10%)
 - DB::table('film')->select('film_id, title')->get()
 - DB::select("select * from film");


Login
1. Model User
 - point ke table users (by default)

2. Auth::attempt()


php artisan cache:clear
php artisan 

http://laravel_tot.test/password
- manually generate pssword (hashed)
- \Hash::make('1234');

Middleware
- AuditTrail
table: audit_trail
- id (pk) int auto_increment
- user_id var(25)
- created_at datetime
- updated_at datetime
- url var(100)
- data
- prev_url var(100)
- ip


 

Revision day #4:
- create larapro.test
- adminlte
- layout
 - starter.html
 - @yield('body')

- login / authentication
 - middleware (login)
 - middleware (AuditTrail)
 - table: audit_trail

- sakila DB
- Film 
 - pagination
 - paginate(20) alt. (all() / get())
  - $films->links()
 - search
  - combination: title dan descr

Day 5
Model Relationship
 - one to one
 - one to many
 - many to many (middle table)
 
- Query builder
- CRUD
 - validation (Validation::make())
 - $req->validate()
- API
 - JSON
 

One to One

table phone:
id (pk)
user_id (fk)

table user:
id (pk)

User -> phone
 - hasOne(Phone)
 - 1 user ada 1 phone
 - PK dan FK

(inverse)
Phone -> User
 - belongsOne(User)

One to Many
table customer:
 customer_id (pk)
 - hasMany(Rental)

table rental:
 rental_id (pk)
 customer_id (fk)
 - belongsTo(Customer)


Many to Many
table: film
 - belongsToMany(FilmActor)

table: film_actor
 - belongsToMany(Film)

gitlab.com/azman1204

Borang Penilaian Keberkesanan Latihan

Training evaluation ยท LARAVEL TRAINING (BEGINNER - INTERMEDIATE)

Log in with the account you registered for this training to fill in the survey.

Log in to fill in the survey

Attendance

Registration closed
This training ended on 22 Nov 2021, so new attendance can no longer be registered.

Students (8)

# Name
1. PUTERI SYASYA ATIQAH BINTI AZMI
2. Mohd Sukri bin Muhammad Bakri
3. Azizi bin Harun
4. Banu A/P P Ochatewan
5. Fasihah binti Mansor
6. Norazian Binti Zainal Abidin
7. Mohd Shuhaimi Othman
8. Sulaiha Binti Suhod