Sie sind auf Seite 1von 40

Introduce The

Framework
Web Framework
Programming
Semester Genap 2016/2017

Universitas Surabaya
Requirements Laravel 5.4

PHP >= 5.6.4


OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
XML PHP Extension

Usually this requirements included in newest XAMPP


version
Two steps to Install Laravel
Composer way
First, install COMPOSER (http://getcomposer.org) in your PC / Server.
After that, follow the installation instruction at https://
laravel.com/docs/5.4/installation via Composer Create-Project

Easiest Way
Go to Next Slide
Installing Laravel 5.4
(The Easiest Way)

l
Copy & extract
file wfp.zip into
your htdocs
directory

Name of
l

directory
represented
name of project
Installing Laravel
(The Easiest Way)

Write php artisan to access all of laravel


l

console command. php artisan -V, untuk


mengecek versi dari laravel.
Installing Laravel
(The Easiest Way)

If you cant
find shell in
XAMPP Control
Panel, you can
access into
directory
XAMPP and
find
xampp_shell.
bat
Installing Laravel
(The Easiest Way)
l
We must check that directory storage & bootstrap/cache
have permission to write file inside this directory.

l
Open url http://localhost/wfp/public
l
Done

Bila tidak sesuai write permission bisa dilakukan configurasi dengan syntax icacls seperti link berikut:
http://stackoverflow.com/questions/12725322/alter-folder-permission-in-windows-command-line
It's Time to
Study
Something
Amazing
Exploring Laravel structure
https://laravel.com/docs/5.4/structure
Exploring Laravel structure
l
App
l
This directory holds all our application's logic. We will
put our controllers, services, filters, commands and
many other custom classes here.
l
Bootstrap
l
This folder has some files that are used to bootstrap
Laravel (view). The cache folder is also placed here.
l
Config
l
When we want to configure our application, check out
this folder. We will configure database, mail, session,
etc. here.
l
Database
l
As the name implies, this folder contains our database
migrations and database seeders.
Exploring Laravel structure
l
Public
l
The public folder contains the application's images, CSS,
JS and other public files. (view)
l
Resources
l
We should put our views (.blade.php files), raw files and
other localization files here.
Storage
l

l
Laravel will use this folder to store sessions, caches,
templates, logs, etc.
l
Tests
l
This folder contains the test files, such as PHPUnit
files.
l
Vendor
l
Composer dependencies (such as Symfony classes,
Addition Laravel Structure 5.4
l
Routes
l
Laravel will use this folder to route your url to your Controller
file.
l
The `web.php` file contains routes that the `RouteServiceProvider`
places in the `web` middleware group, which provides session state,
CSRF protection, and cookie encryption. If your application does not
offer a stateless, RESTful API, all of your routes will most likely be
defined in the `web.php` file.
l
The `api.php` file contains routes that the `RouteServiceProvider`
places in the `api` middleware group, which provides rate limiting.
These routes are intended to be stateless, so requests entering the
application through these routes are intended to be authenticated via
tokens and will not have access to session state.
l
The `console.php` file is where you may define all of your Closure
based console commands. Each Closure is bound to a command
instance allowing a simple approach to interacting with each
command's IO methods. Even though this file does not define HTTP
routes, it defines console based entry points (routes) into your
application.
Request from users to server

Where is file controller?

File Controller
Logic
Algorithm
Data Structure
Object Oriented Programming

Response from server to user Database


SP
View
Trigger
Query
View
Javascript
CSS
HTML
It is simple, if
you
know about
routing
Understand routing
One of the most important files of Laravel is routes.php.
l

This file can be found at Laravel/app/Http/routes.php


We use this file for "routing".
l

Routing means that you will tell Laravel to get URL requests
l

and assign them to specific actions that you want.

This File is automatically loaded by the framework


l

It only works
in Laravel 5.2
or before
version !
Understand routing in Laravel
5.4
https://laravel.com/docs/5.4/routing
One of the most important files of Laravel is routes.php.
l

This file can be found at Laravel/app/routes/web.php


We use this file for "routing".
l

Routing means that you will tell Laravel to get URL requests
l

and assign them to specific actions that you want.

This File is automatically loaded by the framework


l
Inside the web.php

This syntax means that if you


access http://localhost/wfp/ , go
to view with welcome.blade.php
Custom web.php syntax (1)

The router allows you to register routes that respond to


any HTTP verb:

Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);
Custom web.php syntax (2)

For example, you may need to capture a user's ID from


the URL. You may do so by defining route parameters
Frontend
Website
is very cool
Frontend Laravel
is view that everyone
can access your website
without login.
It like a facebook login, google,
gmail login and many website.

Frontend in Laravel Framework


can be found in
resources/view directory.
Inside welcome.blade.php

This file can


implement
HTML tag
Php tag
Blade Template-Tag
CHALLANGE 1

How to Change Laravel


home page
l
Open web.php on your favorite editor
(for example: Sublime)
If we want to edit the home page, we
l

need to modify the welcome view.


All views are stored at the
l

resources/views directory.
Go to the views folder, find a file
l

called welcome.blade.php. It's the


welcome view.
Changing Laravel home page
l
In fact, we can change any page
without returning a view
l
Modify the first route:

to
l
Changing Laravel home page
We have just used a anonymous function to change our
l

home page. In PHP, we called this function: "Closure".


l
We use Closure to handle "routing" in small applications.
In large applications, we use Controllers.

It's recommended that you should always use Controllers


l

because Controllers help to structure your code easier.


For instance, you may group all user actions into
UserController, all post actions into PostsController.
CHALLANGE 2

How to add controller


Adding more pages to our first website
l
The website will have three pages:
l
Home page.
l
About page.
l
Contact page.
We should organize all our pages in
l

PagesController.
Create our first controller by using Artisan

Let's create a controller by running this


l

command:
l
php artisan make:controller PagesController --resource

l
Penjelasan:
l
php artisan make:controller [nama controller]
[attribute]
l
Nama controller harus terdapat kata Controller
diakhir nama.

Kebetulan [attribute] pada laravel 5.2 hanya --resouce


l
Create our first controller by using Artisan

l
By default, Laravel creates a RESTful controller.
Therefore, our PagesController class will have
these actions: index, show, create, store, edit,
update, destroy
l
Create a home action and tells Laravel to return
the welcome view
Using our first controller

Open routes.php file. Change the default


l

route to:
Route::get('/', 'PagesController@home');
l

Penjelasan
1. Route memanggil PageController dengan fungsi Home.
Hasil Pemanggilan First
Controller
Solusi Error tersebut
CHALLANGE 3

Learning Blade
Learning Blade templates
Blade view files have .blade.php file extension
l

Put all Blade templates in resources/views


l

directory
All Blade expressions begin with @. For example:
l

@section, @if, @for, @yield, @extends,


@include, etc.
Blade also supports all PHP loops and
l

conditions: @if, @elseif, @else, @for, @


foreach, @while, etc.
Learning Blade templates
For instance, you can write a if else
l

statement in Blade like this:

Equivalent PHP code:


l
TASK

Create Your Custom


Pages
l
How about trying to add the about and
contact page yourself?
l
Now create a blog about you, that contain
several pages as follows: profile page,
hobbies page, and gallery page

Profile Pages include (seperti membuat CV)


1. Your biography (Full Name, Date of Birth & place, How many
brother/sister, status)
2. Your activity (works, course, etc)

Hobbies Pages berisi berbagai macam hobi Anda

Gallery Page berisi foto-foto Anda atau foto yang Anda sukai

NB: tidak perlu menggunakan akses database.


HomeWork
Apakah yang dimaksud Migration pada
Laravel (20)
Apakah yang dimaksud Seeding pada
Laravel (20)
Bagaimana konfigurasi Laravel dengan
Database MySQL (20)
Bagaimana cara akses ke tabel dalam
Database MySQL (20)
Bonus 20 poin lagi bila bisa menjelaskan dengan baik dan diberikan contoh
implementasi sederhana. Demo 29 Agustus 2016
Thank You

Das könnte Ihnen auch gefallen