Is this driver code correct?
$product = Product::find($id)->with('dsa');
using only this
$product = Product::find($id);
works correctly for me but when I try to add the related table I do not get it and tried it in a thousand ways and nothing. I have the tables related to both my innoDB database I take on the models ..
MODEL
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $fillable = [
'id', 'nombre', 'apellidos', 'nombreyape', 'nacimiento', 'fallecimiento', 'user_id'
];
public function dsa()
{
return $this->hasMany('App\Dsa', 'di', 'id');
}
}
Dsa model namespace App;
use Illuminate\Database\Eloquent\Model;
class Dsa extends Model
{
protected $fillable = [
'user_id', 'di', 'nombre', 'apellidos', 'enlace'
];
public function product()
{
return $this->belongsTo('App\Product', 'id', 'di');
}
}
using this driver
$product = Product::with('dsa')->find($id);
works to show me the full table using
{{ $product->dsa }}
and he returns this to me exactly
[{"id": 10, "user_id": 21, "di": 39, "name": "pepe", "last names": "lorenzo", "link": "example", "created_at" : "2018-10-06 14:50:37", "updated_at": "2018-10-06 14:50:37"}, {"id": 11, "user_id": 21, "di": 39 , name ":" juan "," last name ":" nickname "," link ":" example "," created_at ":" 2018-10-06 14:51:11 "," updated_at ":" 2018-10- 06 14:51:11 "}]
but if I try to call something just like the name for example
{{ $product->dsa->nombre }}
gives me the following error Property [name] does not exist on this collection instance.