Last Updated: January 04, 2021
·
41.16K
· rjacobsen2012

Create Laravel Eloquent model without a primary key

To create an Eloquent model for a legacy table that has no primary key, simply add the following to your model:

/**
 * primaryKey 
 * 
 * @var integer
 * @access protected
 */
protected $primaryKey = null;

/**
 * Indicates if the IDs are auto-incrementing.
 *
 * @var bool
 */
public $incrementing = false;

2 Responses
Add your response

For updating model in Laravel, don't you also have to add namespace like this
namespace App; use Illuminate\Database\Eloquent\Model; class <class name> extends Model

over 1 year ago ·

thank you.

over 1 year ago ·