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;
Written by Richard Jacobsen
Related protips
2 Responses
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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#