B
B
BonBon Slick2016-11-06 15:02:36
Laravel
BonBon Slick, 2016-11-06 15:02:36

Product $product_id returns empty array Laravel 5.3?

This controller entry works with a bang (Laravel 5.3):

public function edit($product_id)
{
  return $product  = Product::find( $product_id );
}

And in the tutorials (old) it returned through:
public function edit(Product $product_id)
{
 return $product_id;
}

And it will return to us all the data of the object, in our case, the product with its ID.
Here is my route :
Route::get( 'product/{id}/edit', '[email protected]' );

Why does it return an empty array, or something like this ( if you write dd() ):
Product {#316 ▼
  #table: "products"
  #primaryKey: "product_id"
  #fillable: array:18 [▶]
  #hidden: []
  #connection: null
  #keyType: "int"
  #perPage: 15
  +incrementing: true
  +timestamps: true
  #attributes: []
  #original: []
  #relations: []
  #visible: []
  #appends: []
  #guarded: array:1 [▶]
  #dates: []
  #dateFormat: null
  #casts: []
  #touches: []
  #observables: []
  #with: []
  +exists: false
  +wasRecentlyCreated: false
}

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tesla, 2016-11-06
@BonBonSlick

Maybe you're misreading the documentation ?
Route::model('id', Product::class);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question