嗨,我正在试图查询我的数据库中表之间的关系。快速概述我的应用程序,我有users,tasks,projects,tasks,statuses和优先级。目前,我希望返回具有客户端名称和状态名称的auth用户项目,可以使用db表中的相关id检索它们。
我几乎正确地返回了所有这些信息,例如,如果我使用项目和客户端查询Auth用户,返回的数据也是正确的,那么我将在回购中进行查询,并让我的控制器使用以下内容:
public function getUserProjectswithClients()
{
return \User::with(array('projects&
我正在使用Laravel 9设计一个反馈网络应用程序,它有两个表,名为users和feedbacks,它们有一对多的关系。我试图使用Laravel实现这一点,但是当我试图使用User模型获取数据时,查询将执行如下所示。
select * from `feedback` where `feedback`.`user_userId` = 1 and `feedback`.`user_userId` is not null
这是错误的。正确的查询应该是,
select * from `feedback` where `feedback`.`userId` = 1 and `feedback`.`us
我对我的模型有一个问题,我试图访问模型属性来回忆刀片中的属性。问题是我不能登录
这是我的模型订单:
<?php
namespace App\Models;
use App\Models\Restaurant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Order extends Model
{
use HasFactory;
protected $fillable=[
'id_use
我在调用$ event-> courts时出错
“消息”:"SQLSTATE42S22:列未找到:'where子句‘中的1054个未知列'courts.events_id’(SQL: select * from courts where courts.events_id =1和courts.events_id不为空)
事件
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\
这些是我的模特
class DateAttribute extends Eloquent{
public function xmlDocument(){
return $this->belongsTo('XMLDocument');
}
}
class XMLDocument extends Eloquent{
public function dateAttribute(){
return $this->hasOne('DateAttribute');
}
}
XMLDocument模型有一个Date
如果我们将放在hasManyThrough上并将其修改如下:
countries
id - integer
name - string
users
id - integer
country_id - integer
website_id - integer
name - string
websites
id - integer
title - string
以users作为中间关系,可以使用country模型上的hasManyThrough()来得到websites
我试了一下,结果出错了。
namespace App;
u
我有一个出版物模型,它属于由用户模型表示的作者。这就是它们的定义:
class Publication extends \Illuminate\Database\Eloquent\Model {
public $incrementing = false;
public function author() {
return $this->belongsTo('App\Models\User');
}
}
我在表中使用了标准的命名约定,因此在发布表中有一个名为user_id的列。
class User extends \Illuminate\Databa
我正在使用Laravel5.1并体验了这个错误
调用未定义方法Illuminate\Database\Eloquent\Collection::votes()
当存储数据时。
商业模式
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Business extends Model
{
public function votes()
{
return $this->hasMany('App\Models\Vote');
}
}
然后将表单POST
我想用eloquent在两个表之间创建一个关系,但我不知道如何进行...
以下是我的两个带关系的模型:
表etablissement:
<?php class Etablissement extends Eloquent {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'etablissement';
public function annulation()
{
return $this->hasMany('Annulat
我有这样的作者模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Author extends Model {
public $timestamps = false;
public function role()
{
return $this->hasOne('App\Role');
}
}
以及如下所示的榜样:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
c
我有两个表-成员和主题。这两个表以一对多的关系相互关联,如下所示:
class Topic extends Eloquent
{
public function member()
{
return $this->belongs_to('Member');
}
}
class Member extends Eloquent
{
public function topics()
{
return $this->has_many('Topic');
我没有使用自动递增的id,而是使用32个字符的唯一id。因此,当我创建一个关系和查询时,我得到了一个null,因为我的FK需要int我的模型
class User extend Eloquent {
public $incrementing = false;
}
class Reservation extend Eloquent {
public $incrementing = false;
}
所以当我查询这个的时候
$reservations = Reservation::with('user')->where('user_id'
我正在尝试实现一个直接在belongsTo上的->withTrashed()作用域的->withTrashed()关系。
这是软删除模式:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class ContractType extends Model
{
use SoftDeletes;
}
这是试图访问合同类型的模型:
<?php
namespace App\Models;
我有这两个类:
<?php
class Client extends Eloquent
{
public function orders()
{
return $this->has_many('Order');
}
}
和Order类:
<?php
class Order extends Eloquent
{
public function client()
{
return $this->belongs_to('Client');
}
}
在
我的应用程序中有两个型号,' User‘& 'MedicineType’(每个用户都属于一个MedicineType)。
我使用belongsTo()和hasMany()在两个模型之间建立了一对多的关系。hasMany()关系工作得很好,但是belongTo()不能工作。有人知道我在哪里犯的错吗?
用户::查找(1)->medicine_type--它什么也不返回
医疗类型::查找(1)返回用户的->users
下面是给模型的代码:
class MedicineType extends Eloquent {
public function
我遇到了一个问题,我在查询模型时得到了一个空值,我有两个模型User.php和Project.php,当我使用tinker和User.php来检查数据是否与我想要的Project.php模型有关系时,但是当我使用Project.php来检查它是否与User.php有关时,我得到了一个空值。
这是我的Project.php代码:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
public $table = "project";
我正在创建一个函数,每次我向RMA票据添加评论时,它都会向用户发送一封电子邮件,但当我提交评论时,我将得到Trying to get property of non-object。
下面我粘贴了来自CommentController的代码和电子邮件功能,如果您想要更多的信息,只需询问,我会发布我能做的。
我得到了这个代码的错误- $mailer->sendRmaTicketComments($comment->ticket->user, Auth::user(), $comment->ticket, $comment);
CommentController码
<?
我有以下移民:
表: bebidas:
class CreateBebidasTable extends Migration{
public function up() {
Schema::create('bebidas', function ($table) {
$table->increments('id');
$table->integer('tipo_id')->unsigned();
$table->string('bebi_name');
我有点被困在这上面..。我有3张桌子:摄影师,语言和languages_spoken (中间表)。
我正试着检索摄影师说的所有语言。我这样定义我的模型:
class Photographer extends Eloquent {
/**
* Defining the many to many relationship with language spoken
*
*/
public function languages() {
return $this->belongsToMany('Language', 'languages_spoken'
我正在尝试创建一个简单的Laravel 5应用程序进行测试。一切似乎都是正确的(数据库、表格等).但是,在试图通过关系查询数据库时,仍然会出现以下错误:
PHP工匠修补程序:
>>> App\Product::first()->name;
=> "Laptop A"
>>> App\Product::first() -> order -> id;
PHP error: Trying to get property of non-object on line 1
>>> App\Product::f
我试图从许多关系中检索数据,我有两个表:
companies: [cid,name,origin]
vehicle_types: [id, type]
他们的枢轴表:companies_vehicle_types: companies_id,vehicle_types_id关系定义:在公司:
public function vehicle_types(){
return $this->belongsToMany('App\vehicle_types');
}
在vehicle_types中
public function companies(){
r
我想使用games模型检索模型giveaway
giveaway:
id
giveaway_games:
id
gameID
giveawayID
games:
id
name
阅读文档,我理解我必须使用hasManyThrough关系,但我不确定我是否正确地使用了它
public function gamesNames(){
return $this->hasManyThrough(Games::class, GiveawayGames::class, 'gameID', 'id');
}
任何帮助都将不胜感激。
我有这样的关系Artist - has many - Album
艺人班:
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Artist extends Model {
public function albums()
{
return $this->hasMany('App\Album');
}
}
专辑班:
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class
我已经创建了一个模型,它具有指向django.contrib.auth.models User模型的外键。我需要检索外键引用的值。但如何做到这一点呢?
我的模型是
from django.contrib.auth.models import User
def FooModel(models.Model):
user = models.ForeignKey(User)
然后我知道我可以使用:
FooModel.objects.get()或FooModel.objects.filter(),但据我所知,它们只会从FooModel返回条目。那么如何从User模型中检索呢?
当我试图在我的页面上使用它时,我得到了以下错误
试图获取非对象的属性
我有两张桌子:
cvicenis
id
title
body
category_id
categories
id
name
我的Cviceni模型:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Cviceni extends Model
{
public function category()
{
return $this->belongsTo('App\Ca