我目前在与Laravel 4的关系方面遇到问题,我在使用数据透视表时遇到错误,该表在一个表上查询,其中两个组件都是单数名称.我创建了一个数据透视表lands_objs并填充它:
模型是:
<?php
class Obj extends Eloquent
{
protected $guarded = array();
public static $rules = array();
public $timestamps = false;
public function land()
{
return $this->belongsToMany('Land');
}
<?php
class Land extends Eloquent
{
protected $guarded = array();
public static $rules = array();
public $timestamps = false;
public function objs()
{
return $this->belongsToMany('Obj');
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我按照标准填充数据透视表的方法.当然存在land,objs和lands_objs表:
<?php
use Illuminate\Database\Migrations\Migration;
class CreateLandsObjsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('lands_objs', …
Run Code Online (Sandbox Code Playgroud) 我正在寻找使用普通表单将ajax请求作为同步请求处理的最有效方法.据我所知,有两种方法可以处理例如新的订单发布请求:
选项1:AJAX检查控制器(为简单起见,验证并省略).
//Check if we are handling an ajax call. If it is an ajax call: return response
//If it's a sync request redirect back to the overview
if (Request::ajax()) {
return json_encode($order);
} elseif ($order) {
return Redirect::to('orders/overview');
} else {
return Redirect::to('orders/new')->with_input()->with_errors($validation);
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,我必须在每个控制器中进行检查.第二种情况解决了这个问题,但对我来说这看起来有些过分.
选项2:让路由器根据请求处理请求检查和asign控制器.
//Assign a special restful AJAX controller to handle ajax request send by (for example) Backbone. The AJAX controllers always show JSON and the normal controllers always redirect like in the old days. …
Run Code Online (Sandbox Code Playgroud) 如何选择multiselect primeng的默认值,需要这个来进行表单更新
代码:
@Component({
template: `<p-multiSelect [options]="cities" [(ngModel)]="selectedCities" ></p-multiSelect>`
})
export class MyComponent {
cities: SelectItem[];
selectedCities= [];
public constructor() {
this.cities = [];
this.cities.push({ label: 'Paris', value:{id:'1',country:'France', name:'paris'} });
this.cities.push({ label: 'Madrid', value:{id:'2',country:'Spain', name:'madrid'} });
this.selectedCities.push({id:'2',country:'Spain', name:'madrid'})
}
Run Code Online (Sandbox Code Playgroud)
当前行为:值在列表中被选中,但标签为空
我实际上在带有Express的node.js中有一个非常小的应用程序,我无法访问req.body.
这是我的app.js
代码:
var express = require('express'),
middleware = require('./middleware'),
mysql = require('mysql'),
app = express();
app.use(middleware.authenticate);
app.use(middleware.getScope);
app.listen(3000);
module.exports = app;
Run Code Online (Sandbox Code Playgroud)
以及带有中间件的文件:
var bcrypt = require('bcrypt'),
mysql = require('mysql');
function authenticate(req, res, next){
console.log(req.body);
next();
}
function getScope(req, res, next){
console.log(req.body);
next();
}
module.exports.authenticate = authenticate;
module.exports.getScope = getScope;
Run Code Online (Sandbox Code Playgroud)
在所有情况下,req.body都是undefined
.
我发送带有x-www-form-urlencoded
协议的Postman数据,在这种情况下是必须的.
谢谢!!
我有一个svg结构,里面有一些形状.我想在单击一个形状时触发一个事件,而在单击一个svg时触发另一个.问题是SVG事件总是被触发.
为了防止这种情况,我禁止事件从形状冒泡.此外,我试图用d3禁用该事件,但似乎无法正常工作.还尝试使用本机javascript代码禁用事件.
超简单代码的一个例子是:
svg结构
<svg id="canvas" xmlns="http://www.w3.org/2000/svg" version="1.1">
<g>
<circle class="shape" r="10" cx="10" cy="10">
</g>
</svg>
Run Code Online (Sandbox Code Playgroud)
javascript代码
d3.select('#canvas').on('click',svgClickEvents);
d3.selectAll('.item')
.on("mouseover",mouseoverItem)
.on('mouseleave',mouseleaveItem);
//click
d3.selectAll('.item',function(){
//when an item is clicked, svgClickEvents must not be fired
d3.select('#canvas').on('click',null); //this should remove the event listener
//also tried with getElementById('canvas').removeEventListener('click',clickEvents,false);
d3.select(this)
.on("click",function() {
d3.event.stopPropagation();
console.log("click circle")
});
});
Run Code Online (Sandbox Code Playgroud)
我知道事件没有被禁用,因为我从clickEvents函数获取console.log()文本警报.
谢谢.
由于没有关于如何使用 Sailsjs 创建连接池的文档,我一直在搜索它,我发现Sails -mysql 适配器确实有任何池配置,但与测试有关:
{
host: process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost',
// (...)
database: process.env.WATERLINE_ADAPTER_TESTS_DATABASE || 'sails_mysql',
pool: true,
connectionLimit: 10,
waitForConnections: true
}
Run Code Online (Sandbox Code Playgroud)
所以我尝试在 Sails 中包含pool: true
到我的connections.js
文件中:
someMysqlServer: {
adapter: 'sails-mysql',
host: '127.0.0.1',
user: 'root',
password: '',
pool: true,
database: 'mydatabase'
},
Run Code Online (Sandbox Code Playgroud)
服务器仍在运行,我从数据库中恢复数据,但我完全不确定我是否设置了连接并抛出了一个池服务。有什么办法可以检查这个功能吗?
谢谢。
目前我在 Laravel 5.2 中使用 Xero API。我想利用 Eloquent 的强大功能来处理这些数据。
实际上,我可以恢复发票,甚至使用链接方法过滤它们,如下所示:
$invoices = XeroPrivate::load('Accounting\\Invoice')
->where('Status', 'DRAFT')
->execute();
Run Code Online (Sandbox Code Playgroud)
如果我执行 a var_dump
,我会得到这种数据:
object(XeroPHP\Remote\Collection)[173]
public 0 =>
object(XeroPHP\Models\Accounting\Invoice)[171]
protected '_data' =>
array (size=31)
'Type' => string 'ACCPAY' (length=6)
'Contact' =>
Run Code Online (Sandbox Code Playgroud)
雄辩的链接方法可以让我执行这样的事情。目前失败了:
$invoices = XeroPrivate::load('Accounting\\Invoice')
->where('Date','>','2016-03-20')
->execute();
Run Code Online (Sandbox Code Playgroud)
检查 Laravel 的文档,假设我可以使用以下命令转换为集合collect
:
$collection = collect($invoices);
Run Code Online (Sandbox Code Playgroud)
$collection
并不能解决问题。现在数据结构不同了但仍然无法使用Eloquent。现在数据是:
object(Illuminate\Support\Collection)[163]
protected 'items' =>
array (size=24)
0 =>
object(XeroPHP\Models\Accounting\Invoice)[171]
protected '_data' =>
array (size=31)
Run Code Online (Sandbox Code Playgroud)
但事实证明,数据是Illuminate\Support\Collection
正确的。
谢谢!