gpt4 book ai didi

laravel - 如何在 laravel 中使用 orderBy 和 with?

转载 作者:行者123 更新时间:2023-12-02 02:56:15 25 4
gpt4 key购买 nike

<分区>

如何使用 orderBy()with() 关系 其中 orderBy 需要使用 with 引入的列()

已更新

return $rank = BusinessDetails::with(['rar' => function ($query) {
$query->orderBy('int_total_ratings_value', 'DESC');
}])
->select('pk_int_business_id', 'vchr_business_name',
'vchr_business_description', 'fk_int_category_id', 'fk_int_location_id')
->get();

商业模式

<?php

namespace App\BackendModel;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\User;
use App\BackendModel\BusinessImages;
use App\BackendModel\Categories;

class BusinessDetails extends Model
{
use SoftDeletes;

const ACTIVATE = 1;
const DEACTIVATE = 0;

public static $days=[
['name'=>'Monday','id'=>1],
['name'=>'Tuesday','id'=>2],
['name'=>'Wednesday','id'=>3],
['name'=>'Thursady','id'=>4],
['name'=>'Friday','id'=>5],
['name'=>'Saturday','id'=>6],
['name'=>'Sunday','id'=>7]
];

protected $dates = ['deleted_at'];
protected $primaryKey = 'pk_int_business_id';
protected $table = 'tbl_business_details';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'vchr_business_name', 'vchr_business_description', 'vchr_telephone_number', 'vchr_company_mobile_number', 'vchr_company_email', 'vchr_contact_person', 'vchr_logo_path', 'fk_int_category_id', 'date_date_of_establishment', 'vchr_website', 'time_open_hours', 'time_close_hours', 'time_lunch_hours','int_closed_on','int_status', 'int_review_status','fk_int_user_id','fk_int_location_id','vchr_map','vchr_holiday'
];


public function rar()
{
return $this->hasOne('App\BackendModel\OverallRating', 'fk_int_business_id', 'pk_int_business_id')
->select('fk_int_business_id', 'float_overall_ratings' , 'int_no_of_ratings', 'int_total_ratings_value', 'int_no_of_reviews', 'int_no_of_like');
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com