- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
你好,我想将一个子板插入板,但这个子板属于用户和板,我正在尝试自动插入板 ID 和用户 ID,但板 ID 无法正常工作这是我的代码:
子板.php
<?php
namespace App;
use App\Thread;
use App\User;
use App\Board;
use Illuminate\Database\Eloquent\Model;
class Subboard extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['subboaName'];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'useId' => 'int',
'boaId' => 'int',
];
/**
* Obtenemos los threads del board.
*
* @return los threads dentro de ese board.
*/
public function thread()
{
return $this->hasMany(Thread::class);
}
public function user()
{
return $this->belongsTo(User::class, 'useId');
}
public function board()
{
return $this->belongsTo(Board::class, 'boaId');
}
}
SubboardController.php(创建方法)
public function subseccion(Request $request)
{
$this->validate($request, [
'subboaName' => 'required|max:25',
'boaId' => 'required',
]);
$request->user()->subboards()->create([
'subboaName' => $request->subboaName,
'boaId' => $request->boaId,
]);
return redirect('/administrar/subsecciones');
}
Subboards.blade.php(我们插入的表单)
<form class="form col-md-12 center-block" role="form" method="POST" action="{{ url('/administrar/subsecciones') }}">
{!! csrf_field() !!}
<div class="form-group{{ $errors->has('selectboa') ? ' has-error' : '' }}">
<select name="boaId" class="form-control input-lg selectpicker" data-live-search="true" title="Selecciona sección" data-style="input-lg btn-default">
@foreach ($boards as $board)
<option value="{{$board->id}}">{{$board->boaName}}</option>
@endforeach
</select>
@if ($errors->has('boaId'))
<p class="help-block">
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Error:</span>
{{ $errors->first('boaId') }}
</div>
</p>
@endif
</div>
<div class="form-group{{ $errors->has('subboaName') ? ' has-error' : '' }}">
<input type="text" class="form-control input-lg" placeholder="Nombre de la subsección" name="subboaName" value="{{ old('subboaName') }}">
@if ($errors->has('subboaName'))
<p class="help-block">
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Error:</span>
{{ $errors->first('subboaName') }}
</div>
</p>
@endif
</div>
<div class="form-group">
<button type="submit" class="btn btn-default btn-lg btn-block">
Añadir
</button>
</div>
</form>
最佳答案
将字段名称添加到$fillable
属性
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'subboaName',
'boaId',
'useId',
];
关于php - Laravel,多个 belongsto 和自动插入 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37854658/
class Owner { static hasMany = Dog } class Sitter { static hasMany = Dog } class Dog { s
如果我有以下型号: module.exports = function (sequelize, DataTypes) { var WorkingCalendar = sequelize.defin
我有这样的问题 - 有 3 个表,例如 Clients、Hats、Tshirts。每个客户都有一顶帽子和一件 T 恤关系。我是这样做的: ` ClientsModel: var $name
我使用 Laravel 5.6,我有 3 个模型: 地区 商店 商家 区域有很多商店: public function stores() { return $this->hasMany('Be
我已经在几个地方看到过要“远离”这一点,但是唉 - 这就是我的数据库的构建方式: class Album extends Eloquent { // default connection
如何制作域类以在 Grails 中创建“共享”数据但不“属于”另一个数据的表?例如,我想制作 2 张 table : 具有 2 个主要列的人员表 名称 - 技能 拉里 - 跳跃,大笑,拳击 curl
当子类可能属于父类中的两个属性之一(但不能同时属于两者)时,我无法理解 Grails 中的 belongsTo - hasMany 关系的概念。 例如: class Store { Integ
我创建了Child域,并为其添加了2个父级。我声明为一位 parent 。我在belongsTo约束的帮助下声明了另一个 parent 。 打包多个 parent class Child {
场景一: 我有两个类: 发表 : class Post { String content Date dateCreated static constraints = { content(blank:
我以为答案是很基本的,但是我对Grails还是很陌生,并且在其他任何地方都很难找到我的问题的答案。 基本上,我有两个域类,用户和事件。事件与用户具有“belongsTo”关系,而用户与事件具有“has
要在 Grails 中创建一对一关系,我可以执行以下操作: class Person { static hasOne = [address: Address] } 在这种情况下,地址表具有其人
有人告诉我,要完成将 $belongsTo 映射到非主键,我会将外键设置为 false 并由另一个论坛上的某人(实际上是 IRC)设置条件。但是,我不认为我这样做是正确的。下面是我正在尝试的 $bel
所以我有这个模型,“票”,其中包含(除其他外)“category_id”列。 为简化起见,以下是我的数据的外观: 门票表 ID 标题 类别编号 1 问题 #1 2 2 问题#2 4 3 问题 #3 1
class Batch extends Eloquent { public function coupons() { return $this->hasMany('Coupon
谁能向我解释在ManyToMany关系中belongsTo的作用是什么?对于OneToOne关系,这很明显:如果删除了“OneToMany”侧(主表)中的记录,则相应的“ManyToOne”(子表)也
我有一些模型正在尝试关联。 一种模型是 Item,一种是 Slide,另一种是 Asset。 项目下方有多个幻灯片。 Assets 基本上是已上传的文件(图像、mp3 等),幻灯片是显示 Assets
我正在尝试保存属于另一个模型的记录。然而,我得到一个错误,指出外键丢失。 CakePHP 文档显示了此工作的示例,但我无法让它工作。 这是表格: echo $this->Form->creat
好的必填信息: DEBUG: ------------------------------- DEBUG: Ember : 1.3.1 DEBUG: Ember Data : 1.0.0-b
我有一个顾问表,它有一个链接到“specilaties”表的外键“specialty_id”。 class Consultant extends AppModel { public $belo
我正在处理 belongsTo 关系,但需要知道如何指定要关联的字段。 我有一个报告和一个汽车表。 汽车表以 ID 字段作为 UI。当对汽车进行报告时,我希望从列表中删除该汽车,以便我使用示波器。 在
我是一名优秀的程序员,十分优秀!