我正试着用Laravel和Vue做一个类似app的博客,但在一个点上卡住了。当开发管理面板时,我想要一个“分配角色”的功能,在那里的管理员可以分配一个特定的角色,如“管理员,版主或作者”为此,我定义了一个关系在用户模型 public function role() {
return $this->hasOne(Role::class);
} 现在在Vue中,我想显示一个表,其中包含所有用户名及其角色。为此,我向laravel服务器发送了一个请求,要求从Users表中获取所有数据,users表具有以下字段 id、名称、role_id、电子邮件、密码、created_at、upda
为了将php变量从laravel传递到vue前端,我创建了一个Javascript类,我使用这个类的静态put方法向前端发送一个关联数组。
<?php
namespace App\Helpers;
class Javascript
{
public static function put($array, $request)
{
//I call this static method to pass backend variables to Vue, from blade I json_encode the payload, assign it to
我想得到4种关系的用户模型的同名,这是为刀片文件,我必须显示所有用户的配置文件数据
所以我可以做$user->person->location;
我得到了这个错误:
Call to undefined relationship [Doctor AS Person] on model [App\User].
如果有其他好的解决方案,请提出建议。
控制器
public function profile()
{
$curr_user = Auth::user();
if($curr_user->hasrole('Doctor
是否也可以在toSearchableArray关系字段中映射。我的意思是,有用户模型,我尝试搜索相关的模型领域,以及喜欢;
/**
* Get the indexable data array for the model.
*
* @return array
*/
public function toSearchableArray()
{
return [
'name' => $this->name,
'plz' => $this->account->zip,
];
}
/*
我使用路由模型绑定来获取用户实例,然后在验证通过后更新它,然后更新属于用户和配置文件之间关系的关联,但是我一直收到一个错误。更新发生在用户身上,但在更新配置文件时失败。从我从文档中了解到的情况来看,这似乎是正确的。我可以使用$user->profile访问配置文件数据,因此在用户模型和UserProfile模型中,这种关系似乎是可以的。
有人能看到这个控制器操作有什么问题吗?
public function update(Request $request, User $user)
{
$this->validate($request, [
'user
我遇到了这样的情况:
用户模型:
public function role() {
return $this->hasOne('App\model\Roles' , 'id' ,'role');
}
public function userMetaData() {
return $this->hasOne('App\model\UserMetaData' , 'user_id' ,'id');
}
public func
数据库里有三张桌子,
-用户
-概况
-教育
用户模型
public function profiledetails()
{
return $this->hasOne('App\Profiledetails');
}
public function educationHasOne()
{
return $this->hasOne('App\Education');
}
轮廓细节模型
public function user()
{
return $this->belongsTo('Ap
得到了一个domain table,它有一个带有domain_hosts_table、server_hosts_table和systems_table的One To Many relationship。到目前一切尚好。
调用表数据:
$domains = Domain::with('domain_host', 'server_host', 'system')->get();
域模型:
public function domain_host()
{
return $this->hasOne('App\DomainHost
我有两个模型:Holiday和HolidayInfo。它们如下所示:
Holiday:
class Holiday extends Model
{
protected $table = 'holidays';
protected $primaryKey = 'holiday_id';
public $timestamps = false;
public function dates(){
return $this->hasOne('App\HolidayDates', 'holiday
我试图找出从数据库中检索结果的最佳方法,比如created_at是最近的,并检查另一个值(在本例中是Temps-> value )是否与特定条件匹配。
例如(一些信息缩写)
地点
+----+---------+
| ID | CITY |
+----+---------+
| 1 | DALLAS |
| 2 | CHICAGO |
| 3 | ATLANTA |
+----+---------+
TEMPS
+----+-------+----------+------------+
| ID | VALUE | CITY_ID | CREATED_AT |
+---
我有一个有相关模型的模型
class A extends Model{
public function niceName()
{
return this->hasOne('App\NiceName2' ...);
}
在控制器中,当我使用子模型检索数据时,结果如下
a和我希望它是aNiceName2。
是否有一种方法为返回的结果有一个别名?在cakePHP中,我知道在关系上有propertyName来设置这一点。拉勒维尔也有类似的特征吗?
谢谢
我正在使用Laravel5.1作为我的新项目智能搜索。我的问题是使用like查询从外键获取数据以搜索该表。我的数据库表是:
category->id, name
search->id, category_id (foreign_key), question, answer, tags
我的模型代码是:类别模型
public function helpcenter() {
return $this->belongsTo('App\HelpCenter');
}
帮助中心模型
public function category() {
return
我有一个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
我已经建立了一个到多个关系,我想检索许多结果,并显示在我的刀片模板。我目前正在获得以下错误Property [job_title] does not exist on this collection instance.
我认为这是因为我试图得到许多结果,虽然只有一个,它是一个集合。我的问题是如何知道什么是循环的关键,以回显我的数据,例如@foreach ($WhatHere? as something)
这是我的密码-
关系
//Client model
public function contact() {
return $this->hasMany(Contact::class
当使用归属关系时,我想知道如何将数据插入枢轴表,我现在可以从数据库读取数据,但我不知道如何将数据存储在数据库中,在invoice_product表中,这里是invoce的代码模型:
class Invoice extends Model
{
protected $fillable = ['title','description','client_id','product_id'];
public function user() {
return $this->hasOne('Ap
嗨,我的数据库里有7个表,
所有6个表都具有来自用户表的user_id,
在用户模型中,我声明hasOne关系如下
public function profiledetailsHasOne()
{
return $this->hasOne('App\Profiledetails');
}
public function educationHasOne()
{
return $this->hasOne('App\Education');
}
public function occupationHasOne()
{