How to return database table name in Laravel

前端 未结 11 571
执念已碎
执念已碎 2020-12-28 13:28

Is there a way that I can get the current database table in use by the model that I\'m in? I see that there is a table() function in Laravel/Database/Eloquent/model.php but

11条回答
  •  情深已故
    2020-12-28 13:44

    Since table is a protected property in the Model class (Laravel >= 5) you will need an instance of your Model.

    Here is a case example:

            DB::table( (new YourModelClassname)->getTable() )
                ->update(['field' => false]);
    

提交回复
热议问题