ݺߣ

ݺߣShare a Scribd company logo
LARAVEL PHP FRAMEWORK
Fejlesszünk mint a profik
FEJLESSZÜNK

Linux
Apache
MySQL
PHP

Laravel
FRÉMWÖRKÖK
‣
‣
‣
‣
‣

Átlátható adatszerkezet
Szép kód, gyors fejlesztés
MVC pattern
Biztonság
Performance eszközök

‣
‣
‣
‣
‣

Csapatmunka
Tesztelhetőség
Bejáratott technikák
Cache
Munkalehetőségek
LARAVEL
Laravel is an open source web application framework written
in PHP 5 and released under the MIT License.
‣
‣
‣
‣
‣
‣
‣
‣
‣

Eloquent ORM
Blade templating engine
Artisan CLI
Migrálás, seedelés
Composer packages
RESTful API
Route Model Binding
Localization
HTML class
FLAT PHP vs. LARAVEL
// functions.php
function sql_connenct() { ... }

// app/routes.php
Route::get('users', 'UserController@showUsers');

function html_start(...) { ... }

// app/models/User.php
class User extends Eloquent {
	
protected $table = 'users';
}

function html_end() { ... }

// users.php
<?php
requery_once('functions.php');
html_start('Felhasználók', true, false);
$users = mysql_query('SELECT * FROM users');
echo '<table style="width: 100%;">';
while($user = mysql_fetch_assoc($users)) {
	
echo '<tr>';
	
	
echo '<td>'.$user['nev'].'</td>';
	
	
echo '<td>'.$user['mail'].'</td>';
	
	
echo '<td>'.$user['tel'].'</td>';
	
echo '</tr>';
}
echo '</table>';
html_end();

// app/controllers/UserController.php
class UserController extends BaseController {
	
public function showUsers() {
	
	
$users = User::all();
	
	
return View::make('users.index')
	
	
	
	
->with('users', $users);
	
}
}
// app/views/users/index.blade.php
<table id="users">
@foreach ($users as $user)
	
<tr>
	
	
<td>{{ $user->nev }}</td>
	
	
<td>{{ $user->mail }}</td>
	
	
<td>{{ $user->tel }}</td>
	
</tr>
@endforeach
</table>
SZERKEZETE
laravel-project/	

	

	

	

Projekt könyvtár

	
	
	
	
	
	
	
	
	
	
	
	

app/	 	
	
	
config/	
	
	
	
controllers/	
	
database/	 	
	
lang/	 	
	
	
models/	
	
	
	
start/	 	
	
	
storage/	 	
	
tests/	 	
	
	
views/	 	
	
	
filters.php	
	
	
routes.php	 	

	
	
	
	
	
	
	
	
	
	
	

	
	
	
	
	
	
	
	
	
	
	

Adatbázis, mail, cache, session, view beállítások
Controllerek: logika, kommunikáció modellekkel
Adatbázis migráció, seedelés
Nyelvi fájlok
Modellek: Eloquent osztályok, adatbázis kommunikáció
Globális, lokális egyéni szabályok, Laravel osztálybetöltések
Ideiglenes fájlok
PHPUnit tesztek
View fájlok (Blade templating engine)
Szűrők, melyeket route-okhoz lehet kötni
Route-ok: lekérésekhez controller társítás, filterek használata

	

public/	
	

	

	

	

	

Laravel bootstrap és publikusan elérhető fájlok: CSS, JS, képek

	

vendor/	
	

	

	

	

	

Third-party függőségek (Composer Dependency Manager)
LARAVEL MŰKÖDÉSE
Böngésző
Routing
Adatbázis
Filtering

Controller

View

Model
LARAVEL A GYAKORLATBAN
Hírportál
‣
‣
‣
‣
‣
‣
‣

Főoldal
Kategória nézet
Hír nézet
Szerző nézet
Admin felület
Hír és kategória között n:m kapcsolat
Hír és szerző között n:m kapcsolat
EER DIAGRAM
MIGRÁLÁS - AUTHORS
<?php
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class CreateAuthorsTable extends Migration {
	
public function up() {
	
	
Schema::create('authors', function(Blueprint $table) {
	
	
	
$table->increments('id');
	
	
	
$table->string('email');
	
	
	
$table->string('password');
	
	
	
$table->string('nev');
	
	
	
	
	
	
$table->timestamps();
	
	
	
$table->softDeletes();
	
	
});
	
}
	
public function down() {
	
	
Schema::drop('authors');
	
}
}
MIGRÁLÁS - AUTHOR-POST
<?php
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class CreateAuthorPostTable extends Migration {
	
public function up() {
	
	
Schema::create('author_post', function(Blueprint $table) {
	
	
	
$table->integer('author_id')->unsigned();
	
	
	
$table->foreign('author_id')->references('id')->on('authors');
	
	
	
	
	
	
$table->integer('post_id')->unsigned();
	
	
	
$table->foreign('post_id')->references('id')->on('posts');
	
	
});
	
}
	
public function down() {
	
	
Schema::drop('author_post');
	
}
}
ELOQUENT
class Author extends Eloquent {
	
protected $table = 'authors';
	
public function posts() {
	
	
return $this->belongsToMany('Post');	 	
	
}
}
class Post extends Eloquent {

	

	
protected $table = 'posts';
	
public function authors() {
	
	
return $this->belongsToMany('Author');	 	
	
}
	
public function categories() {
	
	
return $this->belongsToMany('Category');	 	
	
}
}
class Category extends Eloquent {
	
	
	
	
}

protected $table = 'categories';
public function authors() {
	
return $this->belongsToMany('Post');	 	
}

	

// n:m kapcsolat	

// n:m kapcsolat	

// n:m kapcsolat

// n:m kapcsolat
ROUTING
app/routes.php
Route::get('/',	
	
	
	
	
Route::get('post/{link}',	 	
	
Route::get('categories',	 	
	
Route::get('categories/{id}',		
Route::get('author/{id}',	 	
	

'HomeController@showIndex');
'PostController@showPost');
'CategoryController@showIndex');
'CategoryController@showCategory');
'UserController@showProfile');

Route::group(array('before' => 'auth'), function() {
	
	

Route::get('settings',	
	
Route::post('settings',	

	
	

'UserController@showSettings');
'UserController@postSettings');

});
// admin => app/filters.php
Route::group(array('before' => 'admin'), function() {
	
	
	
});

Route::get('admin',	 	
	
'AdminController@showIndex');
Route::get('admin/new-post',	 'AdminController@newPost');
Route::post('admin/new-post',	'PostController@newPost');
CONTROLLER
class PostController extends BaseController {
	
public function showPost($link) {
	
	
$post = Post::where('link', '=', $link)->with('authors', 'categories')->first();
	
	
return View::make('layouts.post')->with('post', $post);
	
}
}
class CategoryController extends BaseController {
	
public function showIndex() {
	
	
$categories = Category::all();
	
	
return View::make('layouts.categories')->with('categories', $categories);
	
}
	
public function showCategory($id) {
	
	
$category = Category::where('id', '=', $id)->with('posts')->get();	 // eager load
	
	
return View::make('layouts.category')->with('category', $category);
	
}
}
VIEW
// app/views/layouts/post.blade.php
@extends('default')
@section('content')
	
<h1>{{ $post->cim }}</h1>
	
Szerzők:
	
@foreach ($post->authors as $author)
	
	
<div>{{ $author->nev }}</div>
	
@endforeach
	
<br />
	
{{ $post->tartalom }}
@stop
LARAVEL
Szekeres Bálint - valentinx

More Related Content

Laravel - Veszprémi Technology Meetup

  • 3. FRÉMWÖRKÖK ‣ ‣ ‣ ‣ ‣ Átlátható adatszerkezet Szép kód, gyors fejlesztés MVC pattern Biztonság Performance eszközök ‣ ‣ ‣ ‣ ‣ Csapatmunka Tesztelhetőség Bejáratott technikák Cache Munkalehetőségek
  • 4. LARAVEL Laravel is an open source web application framework written in PHP 5 and released under the MIT License. ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ Eloquent ORM Blade templating engine Artisan CLI Migrálás, seedelés Composer packages RESTful API Route Model Binding Localization HTML class
  • 5. FLAT PHP vs. LARAVEL // functions.php function sql_connenct() { ... } // app/routes.php Route::get('users', 'UserController@showUsers'); function html_start(...) { ... } // app/models/User.php class User extends Eloquent { protected $table = 'users'; } function html_end() { ... } // users.php <?php requery_once('functions.php'); html_start('Felhasználók', true, false); $users = mysql_query('SELECT * FROM users'); echo '<table style="width: 100%;">'; while($user = mysql_fetch_assoc($users)) { echo '<tr>'; echo '<td>'.$user['nev'].'</td>'; echo '<td>'.$user['mail'].'</td>'; echo '<td>'.$user['tel'].'</td>'; echo '</tr>'; } echo '</table>'; html_end(); // app/controllers/UserController.php class UserController extends BaseController { public function showUsers() { $users = User::all(); return View::make('users.index') ->with('users', $users); } } // app/views/users/index.blade.php <table id="users"> @foreach ($users as $user) <tr> <td>{{ $user->nev }}</td> <td>{{ $user->mail }}</td> <td>{{ $user->tel }}</td> </tr> @endforeach </table>
  • 6. SZERKEZETE laravel-project/ Projekt könyvtár app/ config/ controllers/ database/ lang/ models/ start/ storage/ tests/ views/ filters.php routes.php Adatbázis, mail, cache, session, view beállítások Controllerek: logika, kommunikáció modellekkel Adatbázis migráció, seedelés Nyelvi fájlok Modellek: Eloquent osztályok, adatbázis kommunikáció Globális, lokális egyéni szabályok, Laravel osztálybetöltések Ideiglenes fájlok PHPUnit tesztek View fájlok (Blade templating engine) Szűrők, melyeket route-okhoz lehet kötni Route-ok: lekérésekhez controller társítás, filterek használata public/ Laravel bootstrap és publikusan elérhető fájlok: CSS, JS, képek vendor/ Third-party függőségek (Composer Dependency Manager)
  • 8. LARAVEL A GYAKORLATBAN Hírportál ‣ ‣ ‣ ‣ ‣ ‣ ‣ Főoldal Kategória nézet Hír nézet Szerző nézet Admin felület Hír és kategória között n:m kapcsolat Hír és szerző között n:m kapcsolat
  • 10. MIGRÁLÁS - AUTHORS <?php use IlluminateDatabaseSchemaBlueprint; use IlluminateDatabaseMigrationsMigration; class CreateAuthorsTable extends Migration { public function up() { Schema::create('authors', function(Blueprint $table) { $table->increments('id'); $table->string('email'); $table->string('password'); $table->string('nev'); $table->timestamps(); $table->softDeletes(); }); } public function down() { Schema::drop('authors'); } }
  • 11. MIGRÁLÁS - AUTHOR-POST <?php use IlluminateDatabaseSchemaBlueprint; use IlluminateDatabaseMigrationsMigration; class CreateAuthorPostTable extends Migration { public function up() { Schema::create('author_post', function(Blueprint $table) { $table->integer('author_id')->unsigned(); $table->foreign('author_id')->references('id')->on('authors'); $table->integer('post_id')->unsigned(); $table->foreign('post_id')->references('id')->on('posts'); }); } public function down() { Schema::drop('author_post'); } }
  • 12. ELOQUENT class Author extends Eloquent { protected $table = 'authors'; public function posts() { return $this->belongsToMany('Post'); } } class Post extends Eloquent { protected $table = 'posts'; public function authors() { return $this->belongsToMany('Author'); } public function categories() { return $this->belongsToMany('Category'); } } class Category extends Eloquent { } protected $table = 'categories'; public function authors() { return $this->belongsToMany('Post'); } // n:m kapcsolat // n:m kapcsolat // n:m kapcsolat // n:m kapcsolat
  • 13. ROUTING app/routes.php Route::get('/', Route::get('post/{link}', Route::get('categories', Route::get('categories/{id}', Route::get('author/{id}', 'HomeController@showIndex'); 'PostController@showPost'); 'CategoryController@showIndex'); 'CategoryController@showCategory'); 'UserController@showProfile'); Route::group(array('before' => 'auth'), function() { Route::get('settings', Route::post('settings', 'UserController@showSettings'); 'UserController@postSettings'); }); // admin => app/filters.php Route::group(array('before' => 'admin'), function() { }); Route::get('admin', 'AdminController@showIndex'); Route::get('admin/new-post', 'AdminController@newPost'); Route::post('admin/new-post', 'PostController@newPost');
  • 14. CONTROLLER class PostController extends BaseController { public function showPost($link) { $post = Post::where('link', '=', $link)->with('authors', 'categories')->first(); return View::make('layouts.post')->with('post', $post); } } class CategoryController extends BaseController { public function showIndex() { $categories = Category::all(); return View::make('layouts.categories')->with('categories', $categories); } public function showCategory($id) { $category = Category::where('id', '=', $id)->with('posts')->get(); // eager load return View::make('layouts.category')->with('category', $category); } }
  • 15. VIEW // app/views/layouts/post.blade.php @extends('default') @section('content') <h1>{{ $post->cim }}</h1> Szerzők: @foreach ($post->authors as $author) <div>{{ $author->nev }}</div> @endforeach <br /> {{ $post->tartalom }} @stop