vitta minicurso laravel - hackathon league of legends

52
INTRODUÇÃO AO LARAVE L

Upload: filipe-forattini

Post on 16-Apr-2017

412 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Vitta Minicurso Laravel - Hackathon League of Legends

INTRODUÇÃO AOLARAVEL

Page 2: Vitta Minicurso Laravel - Hackathon League of Legends

DESENVOLVIMENTO EM TIME

CONVERSA DE GENTE GRANDE

Page 3: Vitta Minicurso Laravel - Hackathon League of Legends

MODEL

VIEWCONTROLER

Page 4: Vitta Minicurso Laravel - Hackathon League of Legends
Page 5: Vitta Minicurso Laravel - Hackathon League of Legends

LARAVELBRINGING PHP BACK =)

Page 6: Vitta Minicurso Laravel - Hackathon League of Legends

Taylor Otwellhttps://github.com/taylorotwellCR

IAD

OR

Page 7: Vitta Minicurso Laravel - Hackathon League of Legends

CON

TRIB

UID

ORE

SDayle Reeshttps://github.com/daylerees

Page 8: Vitta Minicurso Laravel - Hackathon League of Legends

DOCUMENTAÇÃO

ONLINE: http://laravel.com/docs/

GITHUB:https://github.com/laravel/laravel

Page 9: Vitta Minicurso Laravel - Hackathon League of Legends

AMBIENTEA PARTE… MENOS… DIVERTIDA

Page 10: Vitta Minicurso Laravel - Hackathon League of Legends

AMBIENTE WINDOWS

1. INSTALADOR WT-NMP

Page 11: Vitta Minicurso Laravel - Hackathon League of Legends

AMBIENTE WINDOWS

2. EDITE O ARQUIVO DE HOSTSC:\WINDOWS\SYSTEM32\DRIVERS\ETC\hosts

127.1.1.1 meuapp.dev

Page 12: Vitta Minicurso Laravel - Hackathon League of Legends

3. CONFIGURE O NGINXserver {

listen 127.1.1.1;server_name meuapp.dev;

root C:\WT-NMP\WWW\meuapp\public;index index.php;charset utf-8;

location / {try_files $uri $uri/ /index.php?$args;

}

location ~ \.php$ {try_files $uri /index.php =404;fastcgi_split_path_info ^(.+\.php)(/.+)$;fastcgi_pass php_farm;fastcgi_param SCRIPT_FILENAME

$document_root$fastcgi_script_name;include nginx.fastcgi.conf;

}}

Page 13: Vitta Minicurso Laravel - Hackathon League of Legends

AMBIENTE LINUX

1. INSTALAR LEMP

Page 14: Vitta Minicurso Laravel - Hackathon League of Legends

AMBIENTE LINUX

2. EDITE O ARQUIVO DE HOSTS/ETC/HOSTS

127.1.1.1 meuapp.dev

Page 15: Vitta Minicurso Laravel - Hackathon League of Legends

3. CONFIGURE O NGINXserver {

listen 127.1.1.1;server_name meuapp.dev;

root /var/www/html/meuapp/public;index index.php;charset utf-8;

location / {try_files $uri $uri/ /index.php?$args;

}

location ~ \.php$ {try_files $uri /index.php =404;fastcgi_split_path_info ^(.+\.php)(/.+)$;fastcgi_pass php_farm;fastcgi_param SCRIPT_FILENAME

$document_root$fastcgi_script_name;include nginx.fastcgi.conf;

}}

Page 16: Vitta Minicurso Laravel - Hackathon League of Legends

4. CONFIGURE BANCO DE DADOSCRIE UM DATABASE “MEU-APP-DEV”CHARSET: UTF-8 ( UTF8_UNICODE_CI )

5. INSTALE O COMPOSER

6. CRIE UM PROJETO LARAVEL

OU

>_ curl -sS https://getcomposer.org/installer | php

>_ composer create-project laravel/laravel meuapp --prefer-dist

>_ composer global require "laravel/installer=~1.1“>_ laravel new meuapp

Page 17: Vitta Minicurso Laravel - Hackathon League of Legends

7. CONFIGURE O LARAVELTENHA CERTEZA DE TER PERMISSÕES DE ESCRITA NOS DIRETÓRIOS

/MEUAPP/BOOSTRAP/MEUAPP/STORAGE

GERE UMA CHAVE PARA CRIPTOGRAFAR AS SENHAS

/MEUAPP/.ENV

>_ php artisan key:generate

APP_ENV=devAPP_DEBUG=true

DB_HOST=localhostDB_DATABASE=MEU-APP-DEVDB_USERNAME=rootDB_PASSWORD=

Page 18: Vitta Minicurso Laravel - Hackathon League of Legends

7. CONFIGURE O LARAVEL/MEUAPP/CONFIG/APP.PHP

/MEUAPP/CONFIG/DATABASE.PHP'debug' => env('APP_DEBUG', true),

'default' => ‘dev',

'connections' => [ ‘dev' => [ 'driver‘ => 'mysql', 'host‘ => env(‘DB_HOST'), 'database' => env(‘DB_DATABASE'), 'username' => env(‘DB_USERNAME'), 'password' => env(‘DB_PASSWORD'), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', ], ],

Page 19: Vitta Minicurso Laravel - Hackathon League of Legends

7. CONFIGURE O LARAVELATUALIZE AS DEPENDENCIAS DO LARAVEL COM O COMPOSER (SE NECESSÁRIO)>_ composer install>_ composer update -o

Page 20: Vitta Minicurso Laravel - Hackathon League of Legends

MEU PRIMEIRO APPACESSE HTTP://MEUAPP.DEV/

Page 21: Vitta Minicurso Laravel - Hackathon League of Legends
Page 22: Vitta Minicurso Laravel - Hackathon League of Legends

/APP/TODO O CÓDIGO COM A LÓGICA DO BACK-END.

/CONFIG/TODAS AS CONFIGURAÇÕES DO SEU APP.

/DATABASE/SCRIPT CRIADORES DE TABELAS E SEEDERS.

/PUBLIC/ROOT DA ACESSADA PELO USUÁRIO, É AONDE FICAM OS ARQUIVOS PÚBLICOS DO SEU SITE COMO JAVASCRIPT E IMAGENS.

Page 23: Vitta Minicurso Laravel - Hackathon League of Legends

/RESOURCES/ARQUIVOS GERADORES DE ARQUIVOS PÚBLICOS E GERADORES DE RESPOSTAS HTML (VIEWS).

/STORAGE/GUARDA TODOS OS ARQUIVOS DE CONTROLE DO FRAMEWORK COMO SESSÕES E LOGS.

/TESTS/SALVA OS TESTES AUTOMATIZADOS

/VENDOR/PACOTES DE TERCEIROS

Page 24: Vitta Minicurso Laravel - Hackathon League of Legends

/.ENVSALVA SUAS CONFIGURAÇÕES DE AMBIENTE

/COMPOSER.JSONDEFINE AS DEPENDÊNCIAS DO SEU APP

/ARTISANDISPARADOR DE

Page 25: Vitta Minicurso Laravel - Hackathon League of Legends
Page 26: Vitta Minicurso Laravel - Hackathon League of Legends
Page 27: Vitta Minicurso Laravel - Hackathon League of Legends
Page 28: Vitta Minicurso Laravel - Hackathon League of Legends

HACKATHONVAMOS BOTAR A MÃO NA MASSA

Page 29: Vitta Minicurso Laravel - Hackathon League of Legends
Page 30: Vitta Minicurso Laravel - Hackathon League of Legends

FAÇA SEU CADASTRO NA API DA RIOT GAMES:https://developer.riotgames.com/

SALVE SUA API-KEY NO SEU /.ENV

VOCÊ PODE VERIFICAR TODOS OS ENDPOINTS DA API AQUI:

https://developer.riotgames.com/api/methods

RIOT_KEY=11111111-1111-1111-1111-111111111111

Page 31: Vitta Minicurso Laravel - Hackathon League of Legends

CRIE UMA MIGRAÇÃO PARA CRIAR A TABELA DE VERSÃO

ABRA O ARQUIVO GERADO AUTOMATICAMENTE/DATABASE/MIGRATIONS/XXXX_XX_XX_XXXXXX_CREATE_VERSIONS_TABLE.PHP

>_ php artisan make:migration create_versions_table

public function up() { Schema::create('versions', function (Blueprint $table) { $table->increments('id'); $table->string('release')->nullable(); $table->timestamps(); }); }

public function down() { Schema::drop('versions'); }

Page 32: Vitta Minicurso Laravel - Hackathon League of Legends
Page 33: Vitta Minicurso Laravel - Hackathon League of Legends

CRIE UM MODEL PARA ACESSAR O BANCO DE DADOS

ABRA O ARQUIVO GERADO AUTOMATICAMENTE/APP/VERSION.PHP

>_ php artisan make:model Version

Page 34: Vitta Minicurso Laravel - Hackathon League of Legends
Page 35: Vitta Minicurso Laravel - Hackathon League of Legends

CRIE SEEDERS PARA POPULAR AS TABELAS

ABRA O ARQUIVO GERADO AUTOMATICAMENTE/DATABASE/SEEDS/VERSIONSSEEDER.php

ADICIONE A SEGUINTE LINHA NO COMEÇO DO ARQUIVO

VAMOS CRIAR UMA FUNÇÃO QUE: FAÇA UMA PERGUNTA PARA A API E CAPITURE AS VERSÕES DO JOGO SALVE AS VERSÕES NO BANCO DE DADOS

>_ php artisan make:seed VersionsSeeder

use App\Version;

Page 36: Vitta Minicurso Laravel - Hackathon League of Legends
Page 37: Vitta Minicurso Laravel - Hackathon League of Legends

ABRA O ARQUIVO SEEDER/DATABASE/SEEDS/DATABASESEEDER.php

PARA TESTAR O SEEDER PODEMOS A QUALQUER MOMENTO RODAR:

UM ESPECÍFICO SEED:

$this->call(VersionsSeeder::class);

>_ php artisan db:seed

>_ php artisan db:seed --class=VersionsSeeder

Page 38: Vitta Minicurso Laravel - Hackathon League of Legends

CRIE MIGRAÇÕES PARA GERAR AS TABELAS

ABRA O ARQUIVO GERADO AUTOMATICAMENTE/DATABASE/MIGRATIONS/XXXX_XX_XX_XXXXXX_CREATE_CHAMPIONS_TABLE.PHP

>_ php artisan make:migration create_champions_table

Schema::create('champions', function (Blueprint $table) { $table->increments('id'); $table->integer('riot_id')->index(); $table->string('name'); $table->string('title'); $table->string('key'); $table->string('image')->nullable(); $table->string('tags')->nullable(); $table->string('stats')->nullable(); $table->text('enemytips')->nullable(); $table->text('lore')->nullable(); $table->timestamps(); });

Page 39: Vitta Minicurso Laravel - Hackathon League of Legends

CRIE UM MODEL PARA ACESSAR O BANCO DE DADOS

VAMOS JÁ TAMBÉM CRIAR O SEEDER PARA OS CHAMPIONS

ABRA O ARQUIVO GERADO AUTOMATICAMENTE/DATABASE/SEEDS/VERSIONSSEEDER.php

E CRIAREMOS UMA FUNÇÃO QUE: CAPTURE OS CHAMPIONS SALVE OS CHAMPIONS COM INFORMAÇÕES ATUALIZADAS DA ÚLTIMA

VERSÃO

>_ php artisan make:model Champion

>_ php artisan make:seed ChampionsSeeder

Page 40: Vitta Minicurso Laravel - Hackathon League of Legends

DICAS PARA FAZER A FUNÇÃO:ENDPOINT:

PARA CONSEGUIR A FOTO DO PERSONAGEM USE:

“https://global.api.pvp.net/api/lol/static-data/br/v1.2/champion?champData=all&api_key=“.env(“RIOT_KEY)

http://ddragon.leagueoflegends.com/cdn/{VERSÃO}/img/champion/{NOME}.png

Page 41: Vitta Minicurso Laravel - Hackathon League of Legends
Page 42: Vitta Minicurso Laravel - Hackathon League of Legends

AGORA VAMOS VISUALIZAR AS INFORMAÇÕES QUE CONSEGUIMOS!

CRIE UM DIRETÓRIO:/RESOURCES/VIEWS/LAYOUTS/

CRIE UM ARQUIVO:PUBLIC.BLADE.PHP

Page 43: Vitta Minicurso Laravel - Hackathon League of Legends
Page 44: Vitta Minicurso Laravel - Hackathon League of Legends

CRIE UM DIRETÓRIO:/RESOURCES/VIEWS/CHAMPIONS/

CRIE OS ARQUIVOS:INDEX.BLADE.PHPSHOW.BLADE.PHP

Page 45: Vitta Minicurso Laravel - Hackathon League of Legends
Page 46: Vitta Minicurso Laravel - Hackathon League of Legends
Page 47: Vitta Minicurso Laravel - Hackathon League of Legends

AGORA TEMOS QUE CRIAR O CONTROLLER:

VÁ PARA O ARQUIVO GERADO AUTOMATICAMENTE:/APP/HTTP/CONTROLLERS/CHAMPIONSCONTROLLER.PHP

NO COMEÇO DO ARQUIVO CHAME:

>_ php artisan make:controller ChampionsController

use App\Champion;

Page 48: Vitta Minicurso Laravel - Hackathon League of Legends

NO MÉTODO INDEX:

NO MÉTODO SHOW:

public function index() { $champions = Champion::all(); return view(‘champions.index')->with('champions‘,$champions); }

public function show($id) { $champion = Champion::find($id) return view('champions.show')->with('champion',$champion); }

Page 49: Vitta Minicurso Laravel - Hackathon League of Legends

AGORA VAMOS CRIAR AS ROTAS:

VÁ PARA O ARQUIVO GERADO AUTOMATICAMENTE:/APP/HTTP/ROUTES.PHP

ADICIONE AS SEGUINTES LINHAS:Route::get('/','ChampionsController@index');Route::get('/champions/{id}','ChampionsController@show');

Page 50: Vitta Minicurso Laravel - Hackathon League of Legends
Page 51: Vitta Minicurso Laravel - Hackathon League of Legends
Page 52: Vitta Minicurso Laravel - Hackathon League of Legends

SUA VEZ!

DIVIDAM-SE EM DUPLAS E FAÇAM COMPLETEM OS DESAFIOS:

FAZER GRÁFICOS DOS ATRIBUTOS DOS CHAMPIONS

FAZER UM CRIADOR AUTOMÁTICO DE TIMES