我有一个多到多的数据库关系,建立在现有的Laravel安装之间的用户和机构。
在前端,我使用一个下拉筛选器将一个agency_id发送到服务器,该服务器应该通过这个agency_id变量过滤/返回所有用户。
我的模型:User.php
/**
* The agencies that belong to the user.
*/
public function agencies()
{
return $this->belongsToMany('App\Agency');
}
Agency.php
/**
* The users that belong to t
我有一个包含关系的产品表:specValues
在我的产品模型中:
public function specValues(){
return $this->morphMany('App\Models\SpecValue', 'specvalued');
}
在have中的specValues中:
class SpecValue extends Model
{
use Cachable;
protected $table = 'specvalued';
protected $fillable = ['fi
我有一个模型的关系方法,它有一个基于模型本身属性的条件。 // ProductController.php
public function show($id, Request $request) {
$product = Product::find($id);
if ($request->exists('optionValues') {
$product->load('optionValues');
}
}
// Product.php
public fun
嗨,伙计们,我想问问你们之间的关系.
我的store模型
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class Store extends Model
{
protected $table = 'stores';
public function address(){
return $this->morphOne('App\Model\Address', 'addressable');
}
}
我对急于装货有意见。
我有两个模特:
class Provider extends Model
{
/**
* Get the currency record associated with the provider.
*/
public function currency()
{
return $this->hasOne('App\Currency', 'tabcur', 'poucur')->where('tabcol','$DEV');
我有两个表:'Author‘和'Book',有以下简单的关系:
class Author extends Model
{
public function books() {
return $this->hasMany('App\Book');
}
}
class Book extends Model
{
public function author() {
return $this->belongsTo('App\Author');
}
}
图书模型有一个属性
我在数据库里有几张桌子。我尝试在QuizSubmissionController中创建关系,以获得未回答提交的问题。我能写一些像$quiz_submission->quiz->questions()->whereDoesntHave('answers')或whereNotExist('submission_answers')这样的东西吗?
我在这里的亲戚:
// Quiz Class
public function category()
{
return $this->belongsTo(Category::class);
我有两张桌子,tutorial:id,title和tutorial_tags:id,tutorial_id,title
tutorial模型中的关系定义如下:
function TutorialTag(){
return $this->hasMany('App\TutorialTag');
}
我想把tutorials和tutorial_tags连接起来,就像这样(请忽略语法错误):
select tutorials.* , tutorial_tags.* from `tutorials` left Join
`tuotrial_tags` ON
我有两张桌子:Calendar和User。Calendar与User有一对多的关系,User通过parentID与自身有关系。
//model Calendar.php
public function users()
{
return $this->belongsTo(User::class,'userID');
}
//model User.php
public function parent()
{
return $this->belongsTo(self::class,'paren
我有两个表,users和jobs。用户拥有一个作业: 从用户模型: public function getJobs(){
return $this->belongsTo('App\Jobs','operative_id','id');
}
public function getIncompleteJobs(){
return $this->belongsTo('App\Jobs','operative_id','id')
->where('job
我不能让它工作,也许我仍然不清楚。 //get the Schools of the local government selected
$churchs = Church::with(['confirmed' => function($q){ $q->where('status', 1);}])
->where('state_id', request('state'))->get();
return response()-
日安。正如我在这篇文章中所解释的,我想从这个表中做一些有意义的事情。我决定采取雄辩的方式。我能够得到不同的类别如下所示。如何循环遍历属于特定类别的每个标题?例如,在表单中获取它:
CatA
Title 1
Title 5
CatB
Title 2
Title 3
Title 4
我的代码如下所示
public function type(Request $request){
$details = [];
$categories = Category::distinct()->get(['category']); //Get the distin
我正在对Laravel应用程序进行一些多租户更新,但在尝试将特定的团队ID从另一种方法传递到模型上的方法时遇到了一个问题。
示例:
主计长:
$waitTime = $booking->estimatedWaitTime($teamId);
在预订模式中:
public function queueLength()
{
$booking = $this->todaysBookings;
foreach ($bookings as $booking) {
// Calculate the length of all bookings
}
}
我和拉拉的关系有问题。
我有三个模特:
城市-(HasMany)->诊所-(HasMany)->Stock
股票-(BelongsTo)->Clinic-(BelongsTo)->City
我需要所有有股票的城市,看起来像股票->城市。我可以编写sql查询:
SELECT ct.id, ct.name
FROM CfgCity as ct
RIGHT JOIN lr_clinics AS cl ON(ct.id=cl.city_id)
RIGHT JOIN lr_clinic_stocks AS st ON(cl.id=st.clinic_id)
WHERE st
我在紧急装货时遇到了麻烦。假设我有成员、TrainingCategory、TrainingCategoryResult和注册的模型
成员模型:
public function registration() {
return $this->hasMany('Registration', 'member_id');
}
public function trainingResults(){
return $this->hasMany('trainingResult', 'member_id');
}
publ
我有一个BuildingImage模型,它与BuildingType有一个OneToOne关系:
BuildImage模型:
/**
* Get the source type of the Building Image.
*/
public function type()
{
return $this->hasOne('App\BuildingType');
}
BuildingType模型:
/**
* Get the Building Image that owns the building type.
*/
public function buil