现在我有这个代码来检查 Eloquent 模型连接到哪个表。
$s = new Something();
dd($s->getTable());
Run Code Online (Sandbox Code Playgroud)
无论如何我可以在不实例化新Something对象的情况下获得表?
我在想像这样的代码:
Something::getTable();
Run Code Online (Sandbox Code Playgroud)
但是会有..should not be called statically误差。
class SampleELoq extends Model
{
use SoftDeletes;
public function conditionFields() {
return $this->belongsToMany('App\EloquentModel\ConditionField');
}
}
Run Code Online (Sandbox Code Playgroud)
nameSpace 是 SampleELoq 的命名空间
$Eloq = $nameSpace::find(1);
$table = with(new $nameSpace->conditionFields)->getTable();
print_r(Schema::getColumnListing($table));
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得conditionFields的表名?