As I am not sure, is it possible to create models with DB Class instead of Eloquent? I want to stay away from 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类的方法组成的模型类.
只需像这样在app/models/MyModel.php
内创建你的模型
class MyModel{
public static function getMyData(){
return DB::table('users')->select('column')->get();
}
}
then you should be fine to call your new class statically:
$data = MyModel::getMyData();
如果你想扩展DB类,你可以,虽然你更可能会想扩展Database/Builder类来扩展功能,但这是一个复杂的话题,我怀疑如果你是在追求这个,你会问一个非常不同的问题.
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