Skip to content

Instantly share code, notes, and snippets.

@catwhocode
Created July 25, 2023 22:50
Show Gist options
  • Save catwhocode/664fa7ed50cf45b4b093d0c5eb4b7e0b to your computer and use it in GitHub Desktop.
Save catwhocode/664fa7ed50cf45b4b093d0c5eb4b7e0b to your computer and use it in GitHub Desktop.
My Model Template for Custom Table
<?php
class Branch extends Model
{
use HasFactory;
// custom table name?
protected $table = 'tbl_branch';
// custom ID field?
protected $primaryKey = 'branch_id';
// disallow mass assignment to these fields
protected $guarded = [];
// allow mass-assignment to these fields
// protected $fillable = [];
// turn off autoincrementing ?
// public $incrementing = false;
// primary key is not an integer ?
// protected $keyType = 'string';
// model will use created_at and updated_at ?
public $timestamps = false;
// custom field name?
// const CREATED_AT = 'creation_date';
// const UPDATED_AT = 'updated_date';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment