Szekeres Bálint - Laravel PHP Framework - Fejlesszünk mint a profik
Minek framework? Miért Laravel? Ha a Hello World PHP-ban már a kisujjadban van, és tudod, hogy mit jelent az n:m adatbázis kapcsolat, akkor elmesélem neked, hogy legyél Laravel sensei!
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
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