lhfzia
Last Updated: March 09, 2018
·
22.38K
· 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;

1 Response
Add your response

29740

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

11 months ago ·