For getting every new tutorial link Please join our telegram group

Part 1 laravel all eloquent model configuration tutorial with example in hindi video

In this tutorial, we will discuss laravel eloquent model all configurations according to conditions these are done in the tables model

laravel model configurations.

  1. table
  2. fillable
  3. guarded
  4. primaryKey
  5. incrementing
  6. keyType
  7. timestamps
  8. timestamp column name
  9. attribute default name

How to customize table name in laravel

laravel rule is table name in a plural form and related model its singular form if over model is not follow these rule than we give table name in $table variable which is protected type let an example over model is 'Student' and table name is 'school_students' than it gives an error if we do not define in model.

protected $table = 'school_students';

Why we use $fillable in laravel

the fillable attribute is used when we mass data store in table throw model. Fillable is array type variable that assigns values that are mass assignable

protected $fillable = [
  'name',
  'email',
  'password',
 ];

Use of laravel $guarded property

guarded attribute is just opposite of fillable attribute it takes attribute name which is not mass assignable guarded and fillable both are use when we mass data assign like when we use to create() method in the controller to create data than it gives an error if we do not use anyone mass assign configuration

protected $guarded = ['role'];

primaryKey configuration in laravel model

How to use different name primary key instead of id then we use this model configuration in this we give a primary key name in $primaryKey variable let our 'students' table primary key name 'student_id'.

protected $primaryKey = 'student_id';

When we not use auto increment id column in laravel table

how to prevent auto increment column from a table in laravel then we use this configuration if in our table no autoincrement column found than pass $incrementing variable false.

public $incrementing = false;

Laravel model keyType property

If in our table primary key not have integer type than we pass $keyType string.

protected $keyType = 'string';

If we not use created_at and updated_at column in laravel table

If we not define created_at and updated_at column in over table than we pass false in $timestamps variable.

public $timestamps = false;

How to change timestamp column name in laravel table

how to change created_at and updated_at column name in laravel table then we use this configuration let our created_at column name start_date than we use.

const CREATED_AT = 'start_date';

Set default value configuration of a column in laravel model

how to define a table column default value by laravel eloquent model than we pass array of columns and its values in $attributes variable.

protected $attributes = [
  'name' => 'default name',
];
php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Related tutorial links