i use this code but i cant send users name in related products i use this code
Creator:
i cant show creator of products for productscontroller i use this:
public function index(){
$products = Product::with(['users'])->get();
return view('products.index', compact('products'));}
and for model product
public function users()
{
return $this->belongsTo(User::class);
}
and for model user
public function products()
{
return $this->hasMany(Product::class);
}
and table
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->unsignedInteger('user_id');
$table->text('description');
$table->integer('weight');
$table->integer('price');
$table->timestamps();
});
this error see
Trying to get property 'name' of non-object (View:
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire