#8 What are Models | Migration files in Laravel 5.6 Tutorial

The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database.

Object-relational mapping (ORM, O/RM, and O/R mapping tool) in computer science is a programming technique for converting data between incompatible type systems using object-oriented programming languages.

Eloquent ORM is laravel’s active record implementation, which simplifies much of your interactions of your system with database

Eloquent models reside in the app directory by default

many developers are confused by the lack of a models directory. We find the word “models” ambiguous since it means many different things to many different people

If you create a model called Post automatically the tablename it deals with will be plural of that, and that is ‘posts’

# Create model through terminal
cd projectname
php artisan make:model modelname ( modelname needs to be singular )
e.g. php artisan make:model Post  # This will create a model called Post.php inside of app directory

# Create model and database migration file together by passing the -m flag
php artisan make:model modelname -m ( modelname needs to be singular )

You can create add change the database column names for posts table inside the model Post.php, like so :  

class Post extends Model {
	// Table name.
	protected $table = 'posts';

	// Primary Key
	public $primaryKey = 'id';

	//Timestamps
	public $timestamps = true;
}

Add your review



Leave a Reply