Commit ba7c0206 authored by José Rômulo's avatar José Rômulo
Browse files

Adiciona model Substituicao e seus relacionamentos

parent 131d87b4
......@@ -3,6 +3,7 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Arquivo extends Model
{
......@@ -11,6 +12,8 @@ class Arquivo extends Model
*
* @var array
*/
use SoftDeletes;
protected $fillable = [
'nome','titulo', 'versao', 'versaoFinal', 'data', 'trabalhoId', 'participanteId'
];
......@@ -19,6 +22,10 @@ class Arquivo extends Model
return $this->belongsTo('App\Trabalho', 'trabalhoId');
}
public function substituicaos(){
return $this->hasMany('App\Substituicao');
}
public function participante() {
return $this->belongsTo('App\Participante', 'participanteId');
}
......
......@@ -15,6 +15,15 @@ class Participante extends Model
public function user(){
return $this->belongsTo('App\User');
}
public function participanteSubstituido(){
return $this->hasMany('App\Substituicao');
}
public function participanteSubstituto(){
return $this->hasMany('App\Substituicao');
}
public function trabalhos(){
return $this->belongsToMany('App\Trabalho', 'trabalho_participante');
}
......
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Substituicao extends Model
{
//
protected $fillable = [
'status',
'tipo',
'justificativa',
'causa',
'participanteSubstituido_id',
'participanteSubstituto_id'
];
public function participanteSubstituido(){
return $this->belongsTo('App\Participante', 'participanteSubstituido_id');
}
public function participanteSubstituto(){
return $this->belongsTo('App\Participante', 'participanteSubstituto_id');
}
public function planoSubstituto(){
return $this->belongsTo('App\Arquivo', 'planoSubstituto_id');
}
public function trabalho(){
return $this->belongsTo('App\Trabalho');
}
}
......@@ -97,4 +97,8 @@ class Trabalho extends Model
public function avaliadors(){
return $this->belongsToMany('App\Avaliador')->withPivot('status', 'AnexoParecer', 'parecer', 'recomendacao', 'created_at');
}
public function substituicaos(){
return $this->hasMany('App\Substituicao');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSubstituicaosTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('substituicaos', function (Blueprint $table) {
$table->bigIncrements('id');
$table->enum('status', ['Finalizada', 'Negada', 'Em Aguardo']);
$table->enum('tipo', ['Completa', 'TrocarPlano', 'ManterPlano']);
$table->text('justificativa')->nullable();
$table->string('causa')->nullable();
$table->unsignedBigInteger('trabalho_id');
$table->unsignedBigInteger('participanteSubstituido_id');
$table->unsignedBigInteger('participanteSubstituto_id');
$table->unsignedBigInteger('planoSubstituto_id');
$table->dateTime('concluida_em')->nullable();
$table->foreign('trabalho_id')->references('id')->on('trabalhos');
$table->foreign('participanteSubstituido_id')->references('id')->on('participantes');
$table->foreign('participanteSubstituto_id')->references('id')->on('participantes');
$table->foreign('planoSubstituto_id')->references('id')->on('arquivos');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('substituicaos');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddSoftdeleteArquivos extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('arquivos', function (Blueprint $table) {
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('arquivos', function (Blueprint $table) {
$table->dropSoftDeletes();
});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment