如何在 Laravel 中实现 BelongsToThrough 关系?
我有表:
**projects_table**
id
**categories_table**
id
project_id
**properties_table**
id
category_id
Run Code Online (Sandbox Code Playgroud)
类别属于项目
public function project(){
return $this->belongsTo('App\Project');
}
Run Code Online (Sandbox Code Playgroud)
属性属于类别
public function category(){
return $this->belongsTo('App\Category');
}
Run Code Online (Sandbox Code Playgroud)
我们怎样才能建立关系?
物业按类别属于项目
public function project(){
return $this->belongsToThrough('App\Project', 'App\Category');
}
Run Code Online (Sandbox Code Playgroud)
编辑问题。
因为我想在我的应用程序上进行多租户,而租户是 PORJECT。我想按项目分离类别和属性。
类别是属于项目财产是属于类别
所以我想通过类别在属性和项目之间建立关系。现在,我需要project_id在类别和属性表上添加:,我认为这不是正确的方法。
我在我的项目中使用sqlsrv 数据库连接,因为我需要连接到 Microsoft SQL 数据库。
我已经成功安装了sqlsrv 驱动程序,因为我可以连接到数据库来检索数据。
但是当我尝试进行 Laravel 迁移时,它显示了一个错误:
Illuminate\Database\QueryException : could not find driver (SQL: select * from sysobjects where type = 'U' and name = migrations)
Run Code Online (Sandbox Code Playgroud)
下面是我的 .env
DB_CONNECTION=sqlsrv
DB_HOST=**********.database.windows.net
DB_PORT=1433
DB_DATABASE=****************_4cd1_9d18_2a7d9ddbcd13
DB_USERNAME=***************_4cd1_9d18_2a7d9ddbcd13_ExternalWriter
DB_PASSWORD=***************
Run Code Online (Sandbox Code Playgroud)
配置文件
extension=php_xmlrpc.dll
extension=php_xsl.dll
extension=php_pdo_sqlsrv_7_nts_x64.dll
extension=php_pdo_sqlsrv_7_nts_x86.dll
extension=php_pdo_sqlsrv_7_ts_x64.dll
extension=php_pdo_sqlsrv_7_ts_x86.dll
extension=php_pdo_sqlsrv_71_nts_x64.dll
extension=php_pdo_sqlsrv_71_nts_x86.dll
extension=php_pdo_sqlsrv_71_ts_x64.dll
extension=php_pdo_sqlsrv_71_ts_x86.dll
extension=php_sqlsrv_7_nts_x64.dll
extension=php_sqlsrv_7_nts_x86.dll
extension=php_sqlsrv_7_ts_x64.dll
extension=php_sqlsrv_7_ts_x86.dll
extension=php_sqlsrv_71_nts_x64.dll
extension=php_sqlsrv_71_nts_x86.dll
extension=php_sqlsrv_71_ts_x64.dll
extension=php_sqlsrv_71_ts_x86.dll
Run Code Online (Sandbox Code Playgroud) 我有一个 html 字符串,我从编辑器获取并存储在数据库中。
<h3><a href="#" rel="noopener noreferrer nofollow"><em><strong>Profile Of User:</strong></em></a></h3><p></p><p>{{user}}</p>
我想从数据库中检索它并将其呈现为 HTML。当我使用 v-html 时,它将呈现为:
<v-card-text v-html="content"></v-card-text>
Run Code Online (Sandbox Code Playgroud)
{{用户}}
如果我有这样的数据属性,如何从数据属性呈现 {{hello}}:
data() {
return {
user: "Lim Socheat",
content:"<h3><a href="#" rel="noopener noreferrer nofollow"><em><strong>Profile Of User:</strong></em></a></h3><p></p><p>{{user}}</p>"
};
},
Run Code Online (Sandbox Code Playgroud)
预期结果:
林索契
因为{{ user }}会被渲染为Lim Socheat
我正在使用现有的数据库,每个表列都包含空格.作为VueJS api的结果,我得到了带有空格的数据键,如下所示:
data = {
Course Trained:"82",
Course trained 2:null,
Delivery Channel:"IA2DC1",
End Date:"2017-05-06",
Full Name:"9",
ID:"1",
Intervention:"IA2",
Number of sessions:"5",
Start Date:"2017-05-02",
Training Orginisation:"2",
}
Run Code Online (Sandbox Code Playgroud)
我的问题是当我尝试使用'v-model'=>'Course Trained'时,整个页面编译错误.
我怎样才能在VueJS中处理这个空间?
PS.我无法删除空格来更改表列名称.因为它与许多关系和第三方应用程序相关联.
我有对象数组的对象
{
"94":[{"Full Name":"Phalla Morn"}],
"95":[{"Full Name":"Pum Chhenghorng"}],
"99":[{"Full Name":"Proen Pich"}]
}
Run Code Online (Sandbox Code Playgroud)
我想将其转换为对象数组:
[
{"Full Name":"Phalla Morn"},
{"Full Name":"Pum Chhenghorng"},
{"Full Name":"Proen Pich"}
]
Run Code Online (Sandbox Code Playgroud)
请帮忙.
我有一对一的多态,我想找出更新现有关系的最佳方式。
class Image extends Model
{
/**
* Get the owning imageable model.
*/
public function imageable()
{
return $this->morphTo();
}
}
class Post extends Model
{
/**
* Get the post's image.
*/
public function image()
{
return $this->morphOne('App\Image', 'imageable');
}
}
class User extends Model
{
/**
* Get the user's image.
*/
public function image()
{
return $this->morphOne('App\Image', 'imageable');
}
}
Run Code Online (Sandbox Code Playgroud)
PostController 中的更新方法
public function update(Request $request, $id)
{
$post = Post::findOrFail($id);
$post->image()->delete();
$post->image()->save(new Image([
'url'=> $request->input('image_url), …Run Code Online (Sandbox Code Playgroud) laravel ×4
relationship ×2
vue.js ×2
arrays ×1
eloquent ×1
javascript ×1
laravel-5 ×1
migration ×1
nuxt.js ×1
object ×1
odbc ×1
one-to-one ×1
polymorphism ×1
sqlsrv ×1
vue-router ×1