Laravel mysql order by with wherehas
I have 2 tables :-
-
users - id,name,email, mobile
-
user_info - id,user_id, store_name, startup_date
-
User Model
class EloquentUser extends Model { protected $table = 'users';
/** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'mobile' ];
}
-
User Info Model
class UserInfo extends Model { use HasFactory, SoftDeletes; public $table = 'user_info';
}
Below is relationship on above 2 tables :-
public function info() {
return $this->hasOne(UserInfo::class,'user_id','id');
}
I want to order on base of startup_date
but it is giving error column not found. Below is the query :-
$reponse = EloquentUser::with('info')->has('info')->orderBy('info.startup_date')->get();
Comments
Post a Comment