我正在成功地查询跟随和它创建130个查询,我想优化它和减少查询的数量,我已经设置了模型和控制器如下。
后模
class Post extends Eloquent {
public function Categories () {
return $this->belongsToMany('Category', 'category_post');
}
}
范畴模
class Category extends Eloquent {
public function posts () {
return $th
我有一个学生模型和与结果模型对应的一对一映射关系。
我有一个eligibleList数组,其中包含要显示其分数的学生id列表。有些学生有结果,而有些学生没有,但我需要显示列表中的所有结果。
我可以使用以下内容检索和显示学生:
$students = Student::with('result:student_id,marks')->whereIn('students.id', $eligibleList)->get();
foreach($students as student) {
if ($student->result != n
如何在Laravel5.1中获得此查询。我有模型菜单,数据库菜单。SQL中的这个查询得到了我想要的结果。
SELECT b.title FROM menus a, menus b WHERE a.id=b.parent_id
同样的事情,我无法得到这个查询
SELECT m.* FROM menus m WHERE m.id in (select m2.parent_id from menus m2)
通常,我知道如何查询和连接三个表,但在这里,我不知道如何实现。问题是,我跟踪了三张桌子:
类别->列
id
name
image
子类别->列
id
table1_id
name
image
子类别->列
id
table2_id
name
image
因此,图像只能添加到Category、Category->Sub-Category或三级Category->Sub-Category->Sub-Sub-Category中。
我想要做的是,当我在页面上显示所有图片时,也会显示它们添加到哪个类别中。
我已经在我的模型中建立了所有的关系,但我不知道如何准确地查询
因此,试图对属于providers模型的用户所能看到的内容进行限定,我定义了这个全局范围:
class Provider extends Model
{
protected static function booted()
{
static::addGlobalScope(new ProviderScope);
}
...
范围定义:
class ProviderScope implements Scope
{
public function apply(Builder $builder, Model $model)
{
好日子,我正试着用雄辩的口才来做这个查询,但我无法使它起作用
我在Server中有两个查询模型,它们是不同的数据库
1用于laravel用户和配置
另一个SAP业务,一个数据库,我想查阅仓库的库存。
当我对用户进行身份验证时,它与其他数据库无关,我只想查阅sap中的数据数据。
但是我想使用备用数据库中的几个表。
我做了一个,但是它重复了关于商店数量等的数据,另一个是失败的。
最后一个是我需要的查询。
如果你能帮我,我会很感激的
第一模型
class Almacen extends Model
{
use HasFactory;
Public function relacion
我有三个表,受益者,问题,Responses..Beneficiary
Benficiary
id name
1 user1
2 user2
3 user3
Questions
id question type
1 what is your hobby hobby
2 address contact
3 phone contact
..questions upto 500 and i need to select according to its type
Response
id beneficia
我有两种模式:优惠和特长,有很多到很多关系:
在Offer.php中
public function specialities()
{
return $this->belongsToMany('App\Speciality');
}
在Speciality.php中
public function offers()
{
return $this->belongsToMany(Offer::class);
}
到目前为止,这很简单。
现在,我正在构建查询,只获得具有特定专业的报价。问题是我使用的是when助手函数,所以我不知道如何访问专业模型:
pub
我有四张桌子,我用了拉拉维尔5.2雄辩的方法
Municipalities
id
name
---------------
Barangays
id
name
municipality_id
----------------
Puroks
id
name
barangay_id
----------------
Households
id
name
purok_id
我还在每个模型中分别附加了hasMany()、belongsTo()关系。
因此:
Municipalities hasMany() Barangays hasMany() Puroks hasMany() Households
我是个初学者,所以我还在努力。
我需要您的帮助,以将此查询转换为Laravel的查询,但最重要的是,这个查询甚至在PhpMyAdmin中也不起作用。
SELECT `candidats.id`
FROM `candidats`,
`candidatures`
WHERE `candidats.id` = `candidatures.candidat_id`
ORDER By `candidatures.date_depot`;
我想要做的是显示所有由etat 指定的候选人,但是这个 etat 属于 candidatures table
在Candidat模型中:
class Cand
我有一个模型用户。它有两种关系方法。
public function destinationTransaction()
{
return $this->hasManyThrough(
Transaction::class,
Account::class,
'object_id',
'destination_id'
)->where('object_type', User::class);
和:
pu
我试图在我正在构建的时间表系统中查询我的模型关系之一。我已经设置了以下模型:
User可以有许多时间表,并且可以属于许多雇员类型。
Timesheet可以有许多行
模型的设置如下:
用户模型:
<?php namespace App\Models\User;
....
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
/**
* The employee types that belong to the user.
*
* @retur
如何使用Eloquent ORM在Laravel中执行此查询?
select * from posts p order by ( select count(*) from likes where flag = 'c' and p.id = post_id ) Desc limit 3
我在我的模型中有这样的关系
Post.php
public function likes(){
return $this->hasMany('Like', 'post_id');
}
Like.php
public function post(){