Automatically detect eloquent table names.
This commit is contained in:
parent
26afb000bf
commit
e540fd3b6d
|
@ -1,5 +1,6 @@
|
|||
<?php namespace Laravel\Database\Eloquent;
|
||||
|
||||
use Laravel\Str;
|
||||
use Laravel\Database;
|
||||
use Laravel\Database\Eloquent\Relationships\Has_Many_And_Belongs_To;
|
||||
|
||||
|
@ -418,6 +419,16 @@ public function dirty()
|
|||
return ! $this->exists or $this->original !== $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the table associated with the model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function table()
|
||||
{
|
||||
return static::$table ?: strtolower(Str::plural(basename(get_class($this))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dirty attributes for the model.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php namespace Laravel\Database\Eloquent\Relationships;
|
||||
|
||||
use Laravel\Str;
|
||||
use Laravel\Database\Eloquent\Model;
|
||||
use Laravel\Database\Eloquent\Pivot;
|
||||
|
||||
|
@ -48,7 +49,7 @@ public function __construct($model, $associated, $table, $foreign, $other)
|
|||
/**
|
||||
* Determine the joining table name for the relationship.
|
||||
*
|
||||
* By default, the name is the models sorted and concatenated with an underscore.
|
||||
* By default, the name is the models sorted and joined with underscores.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
@ -140,7 +141,7 @@ protected function insert_joining($attributes)
|
|||
{
|
||||
// All joining tables get creation and update timestamps automatically even though
|
||||
// some developers may not need them. This just provides them if necessary since
|
||||
// it would be a pain for the developer to maintain them manually.
|
||||
// it would be a pain for the developer to maintain them each manually.
|
||||
$attributes['created_at'] = $this->model->get_timestamp();
|
||||
|
||||
$attributes['updated_at'] = $attributes['created_at'];
|
||||
|
|
Loading…
Reference in New Issue