Skip to content

Instantly share code, notes, and snippets.

@lucassmacedo
Last active April 26, 2017 17:41
Show Gist options
  • Save lucassmacedo/928b4c2a1ef038e453cb8fc02edd2ee0 to your computer and use it in GitHub Desktop.
Save lucassmacedo/928b4c2a1ef038e453cb8fc02edd2ee0 to your computer and use it in GitHub Desktop.
class Film extends Model {
...
public function people()
{
return $this->belongsToMany(Person::class)->select('*')->withTimestamps();
}
...
}
class Person extends Model {
..
public function films()
{
return $this->belongsToMany(Film::class)->withTimestamps();
}
public function type()
{
return $this->belongsToMany(PersonType::class)->withTimestamps();
}
...
Schema::create('films', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('slug')->nullable();
$table->date('release');
$table->string('locale');
$table->time('duration');
$table->enum('color', ['Preto e Branco', 'Colorido']);
$table->longText('sinopse');
$table->string('site')->nullable();
$table->string('cover');
$table->integer('city_id')->unsigned();
$table->foreign('city_id')->references('id')->on('cities');
$table->timestamps();
});
Schema::create('film_person', function($table) {
$table->integer('film_id')->unsigned();
$table->foreign('film_id')->references('id')->on('films');
$table->integer('person_id')->unsigned();
$table->foreign('person_id')->references('id')->on('people');
$table->integer('genre_id')->unsigned();
$table->foreign('genre_id')->references('id')->on('genres');
$table->primary(['genre_id']);
$table->timestamps();
});
Schema::create('person_types', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('slug')->nullable();
$table->timestamps();
});
ex: Figurinista, Diretor, Ator, etc
Schema::create('people', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('slug')->nullable();
$table->string('site')->nullable();
$table->date('birth')->nullable();
$table->enum('sex', ['Masculino', 'Feminino']);
$table->timestamps();
});
Schema::create('person_person_type', function($table)
{
$table->integer('person_id')->unsigned();
$table->foreign('person_id')->references('id')->on('people');
$table->integer('person_type_id')->unsigned();
$table->foreign('person_type_id')->references('id')->on('person_types');
$table->timestamps();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment