Using Laravel (with MySQL) I'm starting with Eloquent relationships. I try to get the related data but I do not get anything. My configuration is as follows:
Migration providers:
Schema::create('proveedores', function (Blueprint $table) {
$table->increments('id');
$table->string('razon_social')->unique();
$table->string('ruc')->unique();
$table->integer('id_rubro')->unsigned();
$table->string('telf_contacto');
$table->foreign('id_rubro')->references('id')->on('rubros')
->onDelete('cascade')
->onUpdate('cascade');
$table->timestamps();
$table->softDeletes();
});
Migration items:
Schema::create('rubros', function (Blueprint $table) {
$table->increments('id');
$table->string('nombre')->unique();
$table->string('descripcion')->nullable();
$table->timestamps();
$table->softDeletes();
});
Provider model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Proveedor extends Model
{
use SoftDeletes;
protected $table = "proveedores";
protected $hidden = ['created_at', 'updated_at', 'estado'];
public function rubro(){
return $this->belongsTo('App\Rubro');
}
}
Model Rubro:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Rubro extends Model
{
use SoftDeletes;
public function proveedores(){
return $this->hasMany('App\Proveedor');
}
}
ControllerController.php driver
$rubro = Proveedor::find(1);
dd($rubro);
Postman returns a series of results, but I can not see the blessed rubric . What should I do?