我有两个模型和两个表。具有数据库结构的第一个模型名称收件箱:第二个模型名称是StudentData数据库结构:我将返回route('/sended')使用我的方法获取所需消息的所有消息:publicfunctiongetMessages($message_type="new"){$user_id=Auth::user()->id;$inbox=newInbox();$paginate=3;switch($message_type){case'sended':$messages=$inbox->where('sender',$user_id)->where('trashed_in_sen
我在商品详情中搜索用户名的查询如下:$data=Store::join('usersASb','b.id','=','stores.user_id')->where('b.name','like','%hazard%')->paginate();它有效。但我使用join来做到这一点。我如何使用belongto来做到这一点?我的店铺模型是这样的:classStoreextendsModel{protected$fillable=['name','user_id',...];publicfunctionuser(){return$this->belongsTo(User::class,'u
我正在连接到一个设计不佳的远程数据库,但我无法以任何方式修改它,我只有读取权限才能获取我需要的数据。它具有以下结构:Products-id-style_id-department_idBrands-id-Name-style_id-department_id如您所见,产品不仅具有brand_id字段,还具有您必须加入的style_id和department_id以便找出产品的品牌。那么我应该如何在我的产品模型中设置我的belongsTo关系才能实现这一点? 最佳答案 最后我做了一个范围来为我做这件事。publicfunctionsc
第一次尝试laraveleloquentrelatioinstip我知道这很简单,但我收到这个错误,不知道它出了什么问题我在数据库中有2个表,news和news_image在数据库中表格:newsid|header|detailsnews_imageid|image|news_id并且有2个模型News,newsImage新闻图像模型:classnewsImageextendsEloquant{protected$table='news_image';publicfunctionnews(){return$this->belongsTo('News');}}新闻模型classNewse
我有这个关系Artist-hasmany-Album艺术家类:hasMany('App\Album');}}专辑类别:belongsTo('App/Artist');}}如果我这样做:$album->artist完全没有问题但是如果我在Album类中更改函数名称而不更改模型/类名称:publicfunctionartistInfo(){return$this->belongsTo('App\Artist');}那么,这将不起作用:$album->artistInfo。它为我返回null附言这不是我的真实模式,但只有在我更改belongsTo的函数名称时才会出现问题。
大家好,以下是我的亲戚用户模型publicfunctionloginlogout(){$this->HasMany("App\Models\LoginLogoutLogs");}这是我的LoginLogoutLogs模型publicfunctionusers(){return$this->belongsTo('App\Models\User');}我正在尝试从这样的用户访问名称$loginLogoutLogs=LoginLogoutLogs::all();foreach($loginLogoutLogsas$loginLogoutLog){dd($loginLogoutLog->use
我正在尝试以Eloquent方式插入记录。在基本情况下很清楚。例如,如果我有一个包含帖子的博客,并且每个帖子都属于一个用户,我可以这样做:$post=newPost;$post->content='Postcontent';$user->posts()->save($post);但是如果我的帖子同时属于用户、类别和组,我应该怎么做呢?我的第一个想法是这样做:$post=newPost;$post->content='Postcontent';$user->posts()->save($post);$group->posts()->associate($post);$cat->posts
我的印象是,当我在我的模型中使用belongsTo关系时,它会返回对象,但我似乎只得到了id。这应该发生吗?这样做有什么好处?这是我的代码:来self的照片模型publicfunctionalbum(){return$this->belongsTo('Album','album');}还有我的PhotosController$photo=Photo::find($id);$album=$photo->album;return'albums/'.$album->folder.'/thumbs/'.$photo->file;不要介意返回,这只是为了测试。我得到一个错误:Tryingtoge
我需要一些有关CakePHP2.2.3的帮助。我有什么我现在有以下设置:帖子有很多附件它工作正常,页面生成有2个查询:SELECT*,`Post`.`id`FROM`posts`AS`Post`WHERE1=1ORDERBY`Post`.`created`DESCSELECT`Attachment`.`id`,`Attachment`.`post_id`,`Attachment`.`created`FROM`attachments`AS`Attachment`WHERE`Attachment`.`post_id`IN(1,2,3,...,n)我想要什么我想将关系扩展如下:Posthas
我有一个表存储,存储有很多库,在库中我有存储的外键store_id。存储表id(PK)库表id(PK)store_id(FK)我对hasMany和belongsTo参数感到困惑,在docs中它说return$this->hasMany('App\Comment','foreign_key');return$this->hasMany('App\Comment','foreign_key','local_key');return$this->belongsTo('App\Post','foreign_key','other_key');hasManyforeign_key和local_k