Skip to content

Commit

Permalink
Curso model and migratiom
Browse files Browse the repository at this point in the history
  • Loading branch information
Lobz committed Jul 26, 2024
1 parent 9ac00f6 commit f143e21
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
22 changes: 22 additions & 0 deletions app/Models/Curso.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Curso extends Model
{
use HasFactory;
protected $table = 'cursos';
protected $fillable = [
'name',
'description'
];

// relationships
public function turmas()
{
return $this->hasMany(Turma::class);
}
}
1 change: 0 additions & 1 deletion app/Models/Topico.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Topico extends Model
{
use HasFactory;
protected $table = 'topicos';
protected $guarded = [];

// relationships
public function exercicios()
Expand Down
4 changes: 4 additions & 0 deletions app/Models/Turma.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function users()
{
return $this->belongsToMany(User::class);
}
public function curso()
{
return $this->belongsTo(Curso::class);
}
public function prazos()
{
return $this->hasMany(Prazo::class);
Expand Down
36 changes: 36 additions & 0 deletions database/migrations/2024_07_25_122648_create_cursos_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('cursos', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description');
$table->timestamps();
});
Schema::table('turmas', function (Blueprint $table) {
$table->foreignId('curso_id')->nullable()->constrained();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('turmas', function (Blueprint $table) {
$table->dropForeign(['curso_id']);
$table->dropColumn('curso_id');
});
Schema::dropIfExists('cursos');
}
};

0 comments on commit f143e21

Please sign in to comment.