我有一个模型设置如下:
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Upload extends Model {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'uploads';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('id', 'user', 'created_at', 'updated_at');
public function mime() {
return $this->hasOne('App\Models\Mime', 'mime');
}
}
Run Code Online (Sandbox Code Playgroud)
当JsonSerialize()被调用时,它返回:
{
"serverPath": "upload/2015/06/06/21/filename.jpg",
"filename": "filename.jpg",
"mime": "92"
}
Run Code Online (Sandbox Code Playgroud)
这92引用了另一个表(App\Models\Mime表示)中的id 和一个type与之关联的字符串.我想92 …
我有一个基本的AngularJS服务设置,如下所示:
app.factory('User', function($resource) {
return $resource('http://api.mysite.com/user/:action:id/:attr', {}, {
history: {
method: 'GET',
params: {
attr: 'history'
}
},
update: {
method: 'POST',
params: {
name: 'test'
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
我这样使用它:
User.history({id: 'testID'}, function(data) {
console.log('got history');
console.log(data);
});
User.update({id: 'me'}, function(data) {
console.log('updated');
console.log(data);
});
Run Code Online (Sandbox Code Playgroud)
问题一: User.update(),尽管将方法设置为POST,仍然继续发送OPTIONS作为请求方法.
虽然Chrome Dev工具报告了请求标头Access-Control-Request-Method:也会发送POST(不确定这是否意味着什么).
问题二:尽管在API代码中设置了这些标头,我仍然在使用CORS时出错:
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS");
Run Code Online (Sandbox Code Playgroud)
如果发出非GET请求,则只会出现此问题.
处理这个问题的正确方法是什么?我也研究了JSONP,但是这是一个RESTful api,我不知道如何解决只有GET支持的问题.
我正在尝试使用两个单独的输入字段,每个输入字段都有自己的模型,其中一个输出字段默认更新另一个的值.
<form id="registerForm" ng-submit="create(email, username, password)">
<input type="text" name="email" placeholder="Email" ng-model="email">
<input type="text" name="username" value="{{email}}" placeholder="Username" ng-model="username">
<input type="password" name="password" placeholder="Password" ng-model="password">
<input type="submit" value="register" class="button" ng-show="!loading">
<input type="submit" value="processing" class="button" disabled ng-show="loading">
</form>
Run Code Online (Sandbox Code Playgroud)
结果是,如果您输入电子邮件,用户输入将自动填充,但如果特别输入用户名,则可以更改用户名.
但这不起作用.相反,ng-model="username"覆盖值attr,无论在那里设置什么.因此,用户名输入保持为空,直到明确输入为止.
有没有办法在这些方面做到这一点,还是需要特殊的指令或什么?
只需要在这里解释Haskell的基本语法,因为我显然缺少一些东西而且找不到任何解释如何正确执行此操作的内容.
鉴于:
data Year = Year Integer
Run Code Online (Sandbox Code Playgroud)
我如何允许添加,例如(Year 2000) + 10哪些会返回Year 2010
我试过了
instance Num Year where
(Year a) + (b) = Year (a + b)
Run Code Online (Sandbox Code Playgroud)
但那没用.试过其他几个,但我认为这是最明显的解决方案.
谢谢你的帮助.
披露此问题基于CS类的问题.期待扩展它.
最初的问题很简单,给定一组n整数,报告整数的n乘积n-1(每次错过一个不同的n_i).它是以线性时间运行的.
例如,一组{1, 2, 3, 4}将报告2 * 3 * 4,1 * 3 * 4,1 * 2 * 4,和1 * 2 * 3.
最简单的解决方案(我能想到)是简单地遍历所有n整数并计算它们的全部(1 * 2 * 3 * 4)的乘积.然后第二次单步执行它们,并使用除法将总乘积除以每个整数.每次报告解决方案(24 / 1, 24 / 2, 24 / 3, 24 / 4).
以上工作并以线性时间运行.教授虽然建议我们也想出办法,不分裂.仍然没有空间限制,只是线性时间限制.我已经考虑过了,但我正在画一个空白.有什么建议?
如果我有一个看起来像这样的服务:
app.factory('User', function($http, User) {
var User = function(data) {
angular.extend(this, data);
};
User.prototype.create = function() {
var user = this;
return $http.post(api, user.getProperties()).success(function(response) {
user.uid = response.data.uid;
}).error(function(response) {
});
};
User.get = function(id) {
return $http.get(url).success(function(response) {
return new User(response.data);
});
};
return User;
});
Run Code Online (Sandbox Code Playgroud)
如何在控制器中获取User在get()函数中创建的内容?
目前我所拥有的是:
app.controller('UserCtrl', function($scope, User) {
$scope.user = null;
User.get($routeParams.rid).success(function(u) {
$scope.user = new User(u.data);
});
});
Run Code Online (Sandbox Code Playgroud)
问题在于UserCtrl获得api响应,而不是从success()工厂返回的值.我更喜欢在工厂制作新用户,而不是将api响应传递给控制器.