laravel eloquent implementation principle
世界只因有你2017-05-16 16:58:22
For example:
<?php
class BusinessWork extends Eloquent
{
/**
* The database table used by the model.
* @var string
*/
protected $table = 'businessWork';
protected $connection = 'mysql';
public $timestamps = 0;
protected $fillable = array(
'businessId',
'title',
'content',
'createAt',
);
}
BusinessWork::find(1); This is how table binding is implemented
PHP中文网2017-05-16 16:58:22
Let me try to answer. I'm not familiar with it, I'm new to it, I hope I'm not misleading.
You can see that BusinessWork inherits Eloquent and has its own tables, operable field properties, etc.
BusinessWork::find(1) is inherited from Eloquent. It also has some common operations such as fetching all records: BusinessWork::all(), which can also be rewritten in BusinessWork.
You can take the time to go out and turn left to Baidu or right to Google to download Laravel's Eloquent ORM documentation.
hope this helps.
習慣沉默2017-05-16 16:58:22
Use the class reflection mechanism to obtain the class name, and then parse it into a table name.
Any questions?