I want to make a CRUD relating these tables in Laravel

1

The database is called: spreadsheet

Category

php artisan make: migration create_table_table

public function up() {
    Schema::create('categoria', function(Blueprint $table){
        $table->increments('id_categoria');
        $table->decimal('costo_hora', 10, 2);
        $table->timestamps();
    });
}

personal

php artisan make: migration create_personal_table

public function up() {
    Schema::create('personal', function (Blueprint $table) {
        $table->increments('id_personal');
        $table->string('paterno',50);
        $table->string('materno',50);
        $table->string('nombre',50);
        $table->unsignedInteger('categoria_id');
        $table->foreign('categoria_id')->references('id_categoria')->on('categoria')->onDelete('cascade');
        $table->timestamps();
    });
}

Salary

php artisan make: migration create_table_hand

public function up() {
    Schema::create('sueldo', function(Blueprint $table){
        $table->increments('id_sueldo');
        $table->decimal('horas', 10, 2);
        $table->decimal('importe', 10, 2);
        $table->string('periodo');
        $table->unsignedInteger('personal_id');
        $table->foreign('personal_id')->references('id_personal')->on('personal')->onDelete('cascade');
        $table->timestamps();
    });
}
    
asked by Carlos 24.08.2018 в 16:38
source

1 answer

0

If I remember correctly in terms of relationships, you should add them in the models you should take into account those from several to several and one to several

this relationship goes in category a category contains several people

public function categoria()
{
    $this->hasMany(Personal::class);
}

is on staff a person has a category

public function personal()
{
  $this->BelongsTo(Categoria::class);
  $this->BelongsTo(Sueldo::class);
}

is in salary a salary is several people

public function sueldo()
{
  $this->hasMany(Personal::class);
}

Surely something else is missing or something has changed, I advise you to look at the documentation of Laravel you have everything there

Greetings

    
answered by 24.08.2018 в 17:36