我希望为我的"Candidate"Eloquent模型添加一个geolocation属性.我想根据他们的位置找到候选人.例如,找到距离旧金山20英里范围内的所有候选人.我的Eloquent模型应该如何将候选人的位置存储在数据库中?
如何根据候选人的位置查询候选人?我正在使用Laravel 5.3.
我正在尝试将 Postgres 和 Laravel 6.x 上的列从类型字符串更改为整数。我试图通过这样的迁移来做到这一点:
public function up()
{
Schema::table('job_listings', function (Blueprint $table) {
$table->integer('company_id')->change();
});
}
Run Code Online (Sandbox Code Playgroud)
当我运行此迁移时,我收到一个错误,该列无法自动转换为整数:
In Connection.php line 664:
SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "company_id" cannot be cast automatically to type integer
HINT: You might need to specify "USING company_id::integer". (SQL: ALTER TABLE job_listings ALTER company_id TYPE INT)
In PDOStatement.php line 123:
SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "company_id" cannot be cast automatically to type integer
HINT: You might need to specify "USING company_id::integer".
In …Run Code Online (Sandbox Code Playgroud) 我正在尝试安装一个软件包 bower install restangular --save
然后Bower要我选择一个Angular版本:
> Unable to find a suitable version for angular, please choose one:
> 1) angular#1.2.6 which resolved to 1.2.6 and has ang-changeorg, angular-cookies#1.2.6, angular-mocks#1.2.6, angular-resource#1.2.6,
> angular-sanitize#1.2.6, angular-scenario#1.2.6 as dependants
> 2) angular#1.2.17-build.226+sha.b6388b3 which resolved to 1.2.17-build.226+sha.b6388b3 and has angular-animate#1.2.17-build.226+sha.b6388b3 as dependants
> 3) angular#* which resolved to 1.2.18 and has restangular#1.4.0 as dependants
> 4) angular#~1.2.0 which resolved to 1.2.19-build.258+sha.ea653e4 and has angularfire#0.7.1 as dependants
> 5) angular#>= 1.0.8 which resolved to 1.3.0-build.2845+sha.e57ad6a …Run Code Online (Sandbox Code Playgroud) 所以我创建了一个新的Sails.js项目,然后运行
$ sails generate api user
Run Code Online (Sandbox Code Playgroud)
喜欢加载页面建议.但是现在当我启动服务器时sails lift出现错误:
sails lift
info: Starting app...
-----------------------------------------------------------------
Excuse my interruption, but it looks like this app
does not have a project-wide "migrate" setting configured yet.
(perhaps this is the first time you're lifting it with models?)
In short, this setting controls whether/how Sails will attempt to automatically
rebuild the tables/collections/sets/etc. in your database schema.
You can read more about the "migrate" setting here:
http://sailsjs.org/#/documentation/concepts/ORM/model-settings.html?q=migrate
In a production environment (NODE_ENV==="production") Sails always …Run Code Online (Sandbox Code Playgroud) 从我的控制器我想选择所有具有"客户端"角色的用户.
我有一个用户模型和一个角色模型.角色属于许多用户,用户属于许多角色.
我已经建立了我的模型,并在模型实例级别有一些辅助函数来获取角色和用户
以下是用户和角色数据库模型:
应用程序/ user.php的
class User extends Authenticatable
{
use Notifiable;
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
// User belongs to many roles
public function roles()
{
return $this->belongsToMany('App\Role')->withTimestamps();
}
// whitelist specific roles
// reject if user does not have given roles
public function authorizeRoles($roles)
{
if ($this->hasAnyRole($roles)) {
return true;
}
abort(401, 'This action is unauthorized.');
}
// Check if a user has a role
public function …Run Code Online (Sandbox Code Playgroud) 我正在尝试按照Michael Hartl的rails教程添加身份验证步骤7.29(http://ruby.railstutorial.org/chapters/sign-up#top).我的项目在本地工作,但当我尝试部署到heroku时,我得到"应用程序中发生错误,并且无法提供页面".这些是我的日志错误:
heroku[api]: Starting process with command `bundle exec rake db:migrate` by connorleech@gmail.com
heroku[run.1285]: Awaiting client
heroku[run.1285]: Starting process with command `bundle exec rake db:migrate`
heroku[run.1285]: State changed from starting to up
heroku[run.1285]: Process exited with status 0
heroku[run.1285]: State changed from up to complete
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=jason-shark-rails-project.herokuapp.com fwd="41.74.174.50" dyno= connect= service= status=503 bytes=
heroku[web.1]: State changed from crashed to starting
heroku[web.1]: Starting process with command `bin/rails server -p 10431 -e $RAILS_ENV`
app[web.1]: …Run Code Online (Sandbox Code Playgroud) 我使用查询字符串参数成功发出请求:
// Works
var Promise = require("bluebird");
var request = Promise.promisifyAll(require("request"));
request.get({
url: 'https://api.angel.co/1/tags/' + encodeURIComponent(friscoLocationTag) + '/startups',
qs: {
access_token: myToken,
order: 'popularity'
},
method: 'GET'
}, function(error, response, body){
// request success
console.log(body);
});
Run Code Online (Sandbox Code Playgroud)
然而,当我尝试答应我的请求时,我失败了:
// Does Not Work
var Promise = require("bluebird");
var request = Promise.promisifyAll(require("request"));
request.get({
url: 'https://api.angel.co/1/tags/' + encodeURIComponent(friscoLocationTag) + '/startups',
qs: {
access_token: myToken,
order: 'popularity'
},
method: 'GET'
}).then(function(error, response, body){
console.log(body);
});
Run Code Online (Sandbox Code Playgroud)
这给出了错误:
}).then(function(error, response, body){
^
TypeError: undefined is not a …Run Code Online (Sandbox Code Playgroud) 我是React和Webpack的新手.我正在设置我的第一个项目,当我尝试运行webpack-dev-server时,我的代码无法编译!
更新
以下答案是正确的.我需要添加'react'到babel加载器预设.您可以在此处查看项目的完整来源:https://github.com/cleechtech/redux-todo
错误:
$ webpack-dev-server
http://localhost:8080/webpack-dev-server/
webpack result is served from /
content is served from ./dist
Hash: d437a155a1da4cdfeeeb
Version: webpack 1.12.14
Time: 5938ms
Asset Size Chunks Chunk Names
bundle.js 1.51 kB 0 [emitted] main
chunk {0} bundle.js (main) 28 bytes [rendered]
[0] multi main 28 bytes {0} [built] [1 error]
ERROR in ./src/index.js
Module build failed: SyntaxError: /Users/connorleech/Projects/redux-todo/src/index.js: Unexpected token (7:16)
console.log(ReactDOM);
ReactDOM.render(<App />,document.getElementById('root'));
Run Code Online (Sandbox Code Playgroud)
SRC/index.js:
var react = require('react');
var ReactDOM = require('react-dom'); …Run Code Online (Sandbox Code Playgroud) 我在使用 Codeception 在 PhpStorm 中为我的应用程序运行测试时出错。我的代码正在通过 Vagrant 运行。
在我的用于 Codeception 测试的index.php的第一行是:
ini_set('xdebug.max_nesting_level', 200);
Run Code Online (Sandbox Code Playgroud)
我通过自制软件安装了 xdebug,这在我的 php 版本输出中:
PHP 7.1.12 (cli) (built: Dec 2 2017 12:15:25) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,虽然我在 PhpStorm 事件日志中收到错误:
Cannot accept external Xdebug connection: Cannot evaluate expression 'isset($_SERVER['PHP_IDE_CONFIG'])'
Run Code Online (Sandbox Code Playgroud)
在我的 PhpStorm 设置中,我将其设置为接受外部连接:
在 php info 我有可用的 xdebug 设置:
$ php -i | grep xdebug
Additional …Run Code Online (Sandbox Code Playgroud) 我有一个简单的package.json,我正在尝试将grunt添加到我的项目中.我已经多次这样做但从未遇到过这个问题
我的package.json:
{
"name": "express-todo",
"main": "server.js",
"dependencies": {
"body-parser": "^1.0.2",
"express": "^4.1.1",
"jade": "^1.3.1",
"mongoose": "^3.8.8",
"nodemon": "^1.0.17",
"request": "^2.34.0"
}
}
Run Code Online (Sandbox Code Playgroud)
然后从命令行我得到错误:
$ npm install grunt --save-dev
npm WARN package.json express-todo@ No repository field.
npm http GET https://registry.npmjs.org/grunt
npm http 304 https://registry.npmjs.org/grunt
npm ERR! Failed to parse json
npm ERR! Unexpected end of input
npm ERR! File: /home/jasonshark/.npm/grunt/0.4.4/package/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm …Run Code Online (Sandbox Code Playgroud) 我的本地计算机上有一个普通的文件网站,并希望使用Sass。在<head>索引页面的中,我有:
<link rel="stylesheet" type="text/css" href="stylesheets/style.scss" />
Run Code Online (Sandbox Code Playgroud)
虽然当我在Chrome中运行此命令时,控制台出现错误:
Resource interpreted as Stylesheet but transferred with MIME type text/plain 来自索引中的链接标记。
如何更改模因类型,以便Chrome呈现我的Sass样式?
我正在尝试开始使用PHPunit。我使用composer init命令创建了一个新的composer.json文件。看起来像这样:
{
"name": "connor11528/stitch-labs-woo-shipment-sync",
"authors": [
{
"name": "Connor Leech",
"email": "connor@stitchlabs.com"
}
],
"require": {}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试安装PHPunit软件包时,出现错误:
[UnexpectedValueException]
Could not parse version constraint README.md: Invalid version string "README.md"
Run Code Online (Sandbox Code Playgroud)
我正在按照PHPunit入门(此处)中概述的说明安装软件包:
$ php -v
$ PHP 7.1.13 (cli) (built: Jan 5 2018 15:31:15) ( NTS )
$ composer self-update
$ composer require --dev phpunit/phpunit ^7
Run Code Online (Sandbox Code Playgroud)
我的文件结构是:
- my-file.php
- composer.json
- README.md
Run Code Online (Sandbox Code Playgroud)
如何克服此错误并安装PHPunit软件包?
php ×5
javascript ×3
laravel ×3
node.js ×3
eloquent ×2
laravel-5 ×2
npm ×2
angularjs ×1
bash ×1
bower ×1
codeception ×1
composer-php ×1
css3 ×1
debugging ×1
geolocation ×1
gruntjs ×1
heroku ×1
phpstorm ×1
postgresql ×1
react-dom ×1
reactjs ×1
request ×1
sails.js ×1
sass ×1
webpack ×1
xdebug ×1