I have this partial code and I don't want to use eloquent due to some performance and slow query, even though I'm using Eager Loading the performance changes little bit. But unlike DB Facade the query is much faster. My problem is how can I access the method inside my model by using DB Facade?
---------------------- Table: user id | fname | lname -----------------------
and this is my model
class User extends Model { public function complete_name() { return $this->fname . " ".$this->lname; } }
but when Im using
$users = DB::table('user')->get();
and loop through it
$result = []; foreach ($users as $user) { $result[] = $user->complete_name(); } return $result;
I cannot access the method "complete_name()". Is there any techniques or style in order for me to access the method inside User class?
https://stackoverflow.com/questions/65807035/i-cannot-access-model-methods-when-using-db-facade-in-laravel January 20, 2021 at 05:50PM
没有评论:
发表评论