【问题标题】:Laravel 5.2 call of non-static Query Builder methods like static methodsLaravel 5.2 调用非静态查询生成器方法,如静态方法
【发布时间】:2016-05-13 21:36:36
【问题描述】:

我正在深入研究 Laravel 5.2 架构。我注意到一件事,在 Illuminate\Database\Eloquent\Model 类中没有一些函数的静态方法,比如插入、更新,但我们像 User::insert() 一样访问它

Model 类中还有另一个函数performInsert()。在这个 User::insert($data) 的例子中 Laravel 如何调用 performInsert()

我在documentation 中阅读了有关外墙的信息。但是在文档中写到该类必须使用Illuminate\Support\Facades\Facade 扩展,但Model 类也不能使用Facade 扩展。有什么帮助吗?

怎么做的?

【问题讨论】:

    标签: php mysql database laravel laravel-5


    【解决方案1】:

    DB::table('users')->insert()这是你应该如何调用函数。

    你没有给它模型。

    见documentation

    【讨论】:

    • 它已经在工作了...没有静态关键字我们如何编写 DB::insert()
    • @AliMehdi 我检查了文档并修改了我的答案检查它。
    • 谢谢...我实际上正在使用模型。当模型被调用时,它就像 User::insert().. 对吗?该模型在后端采用相同的查询生成器。如何
    • 在 Illuminate\Database\Eloquent\Model 内部,没有名为 insert() 的函数
    • 你在哪里以及你在问什么,我现在仍然无法理解:(
    猜你喜欢
    • 2023-02-22
    • 1970-01-01
    • 2013-03-20
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-04
    相关资源
    最近更新 更多