如何创造没有雄辩的Laravel模特? [英] How to create Laravel Model without Eloquent?

查看:91
本文介绍了如何创造没有雄辩的Laravel模特?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我不确定,是否可以使用DB Class而不是Enloquent创建模型?我想离开ORM。

As I am not sure, is it possible to create models with DB Class instead of Eloquent? I want to stay away from ORM.

谢谢

推荐答案

是当然可能的。您不需要扩展任何类来构建一个封装业务逻辑的模型类,并由调用DB类的方法组成。

Yes of course its possible. You dont need to extend any class to make a model class that encapsulates business logic and consists of methods calling the DB class.

只需在 app / models / MyModel.php like this

Just create your model inside app/models/MyModel.php like this

class MyModel{

    public static function getMyData(){
         DB::table('users')->select('column')->get();

    }
}

那么你应该很好您的新课程静态:

then you should be fine to call your new class statically:

$data = MyModel::getMyData();

如果你想扩展DB类,你可以,尽管更有可能你会扩展数据库/生成器类扩展功能,但这是一个复杂的主题,我怀疑你会问一个非常不同的问题,如果这是你以后。

If you wanted to extend the DB class you could, though more likely you would be looking to extend the Database/Builder class to extend functionality but this is a complex topic and I suspect you would have asked a very different question if this was what you were after.

正如我最后一点,我不会指出没有口气,这是Laravel在许多其他伟大的事情中最伟大的事情

As I final note, I wouldn't steer clear of Eloquent, it's the greatest thing about Laravel amongst a lot of other great things

这篇关于如何创造没有雄辩的Laravel模特?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆