我在数据库中有四个表: groups,specialties,lessons,group_lesson。它的结构:
groups
id
specialty_id
name
specialties
id
name
lessons
id
specialty_id
group_lesson (UNIQUE INDEX lesson_id, group_id)
lesson_id
group_id
date
我的模型现在看起来是这样的:
class Group extends Eloquent {
public f
我有以下模型:
namespace App;
use Illuminate\Database\Eloquent\Model;
class forum_category extends Model
{
//
protected $table = 'forum_category';
public function posts()
{
$this->hasMany('App\forum_post');
}
}
和
namespace App;
use Illuminate\Database
我使用的是Laravel 5.2,我需要使用leftjoin从数据库中获取特定值。我使用的代码如下: public function commentList(Request $request)
{
$inputs = $request->all();
$commentList = Comment::select(
'projects_comments.id as comment_id',
'u.name as user_name',
'projects_comments.comme
我有两个模特。
用户:
class User extends Eloquent implements UserInterface, RemindableInterface {
protected $table = 'users';
public function group ()
{
return $this->belongsTo('Group');
}
}
和集团:
class Group extends Eloquent {
protected $table = 'groups
类型错误:传递给Illuminate\Database\Eloquent\Relations\HasOneOrMany::save()的参数1必须是照明\数据库\雄辩\模型的实例,给定的照明\数据库\雄辩\集合的实例
我正计划用个人资料为用户生成假日期。我有两个模型:用户和个人资料。我已经做好了彼此的关系。但当我执行的时候,问题就来了。以上是我运行Seeder时的错误。
这是发现错误的类。
public function run()
{
factory(App\User::class, 40)->create()->each(
function($u
我正试着在拉威尔建立一段关系。 Survey.php: namespace App;
use Illuminate\Database\Eloquent\Model;
class Survey extends Model
{
public function survey_questions()
{
return $this->hasMany(SurveyQuestion::class);
}
} 和SurveyQuestion.php模型: namespace App;
use Illuminate\Database\Eloquent\Mod
下面是这些关系:
评论模型
class Comment extends Model
{
/**
*
* The comment belongs to the post
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function post()
{
return $this->belongsTo('App\Post', 'post_id')->with('
我试着用按关系排序的数据来构建查询。想象一下这个DB结构:
表:站
id
name
...
表: station_status:
id
station_id
status_type_id
date
...
表: status_type:
id
description
...
模型
class Station extends \Eloquent
{
public function stationStatus() {
return $this->hasMany('App\StationStatus', 'station_id',
Edit:
I dont think its the same issue as:
https://stackoverflow.com/questions/40022929/laravel-relationship-error-undefined-property-illuminate-database-eloquent-col
because in that issue hasMany relationship is used which returns an array but i used belongsTo which should return a certain object.
我
在我的Laravel应用程序中,我有一个Faq模型。一个Faq模型可以包含许多Product模型,因此Faq类包含以下函数:
class Faq extends Eloquent{
public function products(){
return $this->belongsToMany('Product');
}
}
在控制器中,我希望能够检索定义关系的类名。例如,如果我有一个Faq对象,如下所示:
$faq = new Faq();
如何确定关系的类名,在本例中为Product。目前我可以这样做:
$className = get
我需要你的帮助,我在Laravel框架之外使用Eloquent和enssegers / laravel-mongodb,我已经成功地正确配置了Eloquent和laravel-mongodb,并且它可以正确地插入和获取结果,但是,当试图修改注册表时,eloquent会抛出以下错误,从而丢失连接名称: Argument 1 passed to Jenssegers\Mongodb\Query\Builder::__construct() must be an instance of Jenssegers\Mongodb\Connection, instance of Illuminate\Da
我一直在用Laravel框架编写一个web应用程序,并且遇到了一个问题,我正在为用户获取特定的数据。我的web应用程序的用户结构是基于一个主用户表,然后我有一个RP表为所有的用户统计数据,如健康,能源,他们拥有的项目,等等。
访问页面时,我试图在上面显示此数据,收到以下错误
Trying to get property of non-object (View: C:\workspace\mainwebsite\resources\views\frontend\home.blade.php)
O只是尝试为用户打印角色扮演表的user_id列(是的,我尝试了其他列,它们输出的结果相同)
<d
我想解决以下问题:
我有好几个模特,比如:
Product
Customer
每个模型都应该有一个或多个具有枢轴数据的Fields。
Field
id
title
type
required
示例:
Product有一个名为video_url的字段,type应该是包含pivot值http://youtube.com/...的string。
Customer有一个名为external_id的字段,type应该是包含pivot值242的integer。
字段应由用户动态添加。用户应该能够决定,该字段是否正在向Product或Customer (甚至更晚一些)
我定义了与我的模型A&B的下列关系:
模型A
namespace App;
use Illuminate\Database\Eloquent\Model;
class A extends Model {
protected $table = 'list';
public function b(){
return $this->hasMany('App\B', 'id', 'id');
}
}
B型
namespace App;
use Illuminate\Database\Eloque
如何删除laravel 4.2上关系表的关系?例如,我有一个名为“类别”的表,它与子类别相关。因此,类别id以外键的形式与子类别相关,并在迁移中映射为级联删除。现在,子类别表与objects表有关联。因此,子类别id作为外键与对象相关,并在delete上映射为级联。现在,当我删除类别,子类别被删除,这是很好的。但是既然子类别被删除了,即使是对象也应该被删除,对吗?但事实并非如此。如何解决这个问题?下面是我的密码。
范畴模型
use Illuminate\Database\Eloquent\SoftDeletingTrait;
class Category extends Eloquent{
我正在尝试找出如何处理下面的关系。我有一个users表,其中包含一些字段,如id、用户名、名称、role_id。我有一个roles表,它有一个id和name字段。
所有用户都有一个角色,并且角色属于所有用户,因此多个用户显然可以具有相同的角色。我在相应的模型中有以下内容。
我正在尝试弄清楚我需要做什么,以便当我为所有用户进行调用时,它将获得角色的名称并显示它,而不是role_id。
class Role extends Eloquent {
public function users()
{
return $this->hasMany('User
我从这里获得参考:
我的模型是这样的:
<?php
namespace App\Models;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use Jenssegers\Mongodb\Eloquent\HybridRelations;
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
class Message extends Eloquent
{
use HybridRelations;
use SoftDeletes;
protected $connect
我正试图定义一个模型突变体
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Custom_fields extends Model
{
protected $table = 'custom_fields';
public function setContentAttribute($value){
return unserialize($value);
}
}
在测试控制器上,尝试
Custom_fields::all()[0]->co
我以表中第一个学生的身份登录。我想使用Eloquent模型检索与我在同一个系的所有学生的列表,并且我还没有向他们发送请求。
//Requestt.php
public function student()
{
return $this->belongsto('App\Student','id', 'Sender_id','Rec_id');
}
//Student.php
public function requestts()
{
return $this->hasMany('App
假设我有这些模型:
用户模型
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'User';
protected $fillable =
[
'username', 'favoriteCol
我所知道的:
$this->$parent->childs(); //we get childs data
我想知道的是:
$this->child->find($id)->parent(); //how to get childs parent without including model in controller | by just using eloquent
下面是我的employee和employeeDependent模型的示例代码:
trait EmployeeRelationships{
public function dependen
我正在尝试从数据库中获得一种结果收集,仍然利用雄辩的优势。
我有一个名为as_inspections的表,一个名为as_green_areas的表和一个名为as_assets的表
每次检查都有一个绿色区域,每个绿色区域都有许多资产。
当我去取检查的时候,我做了这样的事情:
检验模型
namespace App;
use Illuminate\Database\Eloquent\Model;
class Inspection extends Model
{
protected $table = 'as_inspections';
public functio
我的应用程序中有两个型号,' User‘& 'MedicineType’(每个用户都属于一个MedicineType)。
我使用belongsTo()和hasMany()在两个模型之间建立了一对多的关系。hasMany()关系工作得很好,但是belongTo()不能工作。有人知道我在哪里犯的错吗?
用户::查找(1)->medicine_type--它什么也不返回
医疗类型::查找(1)返回用户的->users
下面是给模型的代码:
class MedicineType extends Eloquent {
public function
我有属于IssueCat模型的ContactForm模型。这种关系在模型中定义如下:
class ContactForm extends \Eloquent {
// Add your validation rules here
public static $rules = [
// 'title' => 'required'
];
// Don't forget to fill this array
protected $fillable = [];
public functi
Laravel 5.3,PHP5.6全新的laravel new项目,最小配置。
我做了一个简单的迁移和模型,并尝试通过php artisan tinker向其中播种数据。
我的迁移如下所示:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatesFooTable extends Migration
{
/**
* Run the
<?php
class Cat extends Eloquent {
public function user() {
return $this->belongsTo('User');
}
}
class User extends Eloquent {
public function cats() {
return $this->hasMany('Cat');
}
}
现在:
$cats = Cat::with('user')->get();
执行2个