我有以下结构:
-- node_modules
-- websites
---- common
------- config.js
---- testing
------- test.js
Run Code Online (Sandbox Code Playgroud)
在配置内部我有一些变量设置,使用module.export导出.
我正在尝试node test.js使用以下代码从config.js 运行时检索这些变量:
var configData = require('./common/config.js')
var configData = require('../common/config.js')
Run Code Online (Sandbox Code Playgroud)
他们都没有工作.如何从其他文件夹中检索数据?
我在Laravel有以下系列:
["TheNumbers":[{"episodeID":16818,"episodeNumber":100,"created_at":null,"updated_at":null},{"episodeID":16818,"episodeNumber":210,"created_at":"2017-02-20 21:30:38","updated_at":"2017-02-20 21:30:38"}]
Run Code Online (Sandbox Code Playgroud)
如果我运行以下代码:
$TheEpisode->TheNumbers->pluck('episodeNumber');
Run Code Online (Sandbox Code Playgroud)
我会得到以下结果:
[100,210]
Run Code Online (Sandbox Code Playgroud)
我想保留每个号码的按键,我怎样才能做到这一点?
这是我的预期结果:
[{"episodeNumber":100},{"episodeNumber":210}]
Run Code Online (Sandbox Code Playgroud)
TheEpisode->TheNumbers->reduce(function ($result, $episode) {
$episodeData = (collect())->put('episodeNumber', $episode['episodeNumber']);
$result[] = $episodeData;
return $result;
}));
Run Code Online (Sandbox Code Playgroud) 我在laravel中有以下模型:
TheJobs
- id
- description
- created_at
- deleted_at
- updated_at
TheSeries
- id
- title
- description
- created_at
- deleted_at
- updated_at
TheMovies
- id
- title
- description
- created_at
- deleted_at
- updated_at
mSeriesJobs
- seriesID
- jobID
mMoviesJobs
- movieID
- jobID
Run Code Online (Sandbox Code Playgroud)
以下是以下关系TheJobs:
public function TheSeries() {
return $this->belongsToMany('App\Models\TheSeries', 'mSeriesJobs', 'jobID', 'seriesID');
}
public function TheMovies() {
return $this->belongsToMany('App\Models\TheMovies', 'mMoviesJobs', 'jobID', 'movieID');
}
Run Code Online (Sandbox Code Playgroud)
以下是以下关系TheSeries:
public function TheJobs() {
return $this->belongsToMany('App\Models\TheJobs', …Run Code Online (Sandbox Code Playgroud) 此问题与以下内容有关:Laravel(5.3)Eloquent - 关系问题,请访问此网址以获取更多信息.
我最终得到了以下脚本:
$genres = ['action', 'drama', 'romance'];
$similiarSeries = TheSeries::whereHas('TheGenres', function($q) use($genres) {
$q->whereIn('genre', $genres);
}, '>=', 1);
return $similiarSeries->take(10);
Run Code Online (Sandbox Code Playgroud)
它的作用是:它检查上面变量至少有1个类型的电影,并返回10部电影(如果存在).
问题在于他们的电影是以混乱的顺序返回的,相反,如果他们会优先播放动作,戏剧,浪漫,然后返回只有2种类型的电影(如:戏剧,浪漫或浪漫,行动).然后只有1种类型.
这是否可能在laravel?
这是电影及其类型的示例列表:
Zootopia: Action, Animation, Drama
Toy Story: Action, Drama, Romance
Kung Fu Panda: Action, Animation, Fantasy
Avatar: Action, Drama, Romance
Titanic: Action, Drama, Romance
Avengers: Fantasy, Drama, Fiction
Batman: Adventure
Run Code Online (Sandbox Code Playgroud)
因此,如果我们搜索的电影至少包含['动作','戏剧','浪漫'],
我期待以下内容被退回:
Toy Story (Action, Drama, Romance) (3)
Avatar (Action, Drama, Romance) (3)
Titanic (Action, Drama, Romance) (3)
Zootopia (Action, Drama) (2) …Run Code Online (Sandbox Code Playgroud) 我在我的小项目中使用JWT进行授权(REST API).JWT看起来非常适合我的项目.
假设我有这段代码:
$key = "secret";
$token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ"
$data = JWT::decode($token, $key, array('HS256'));
Run Code Online (Sandbox Code Playgroud)
此代码将返回JWT官方页面上的数组.
但是,如果我尝试运行以下代码:
$key = "secret";
$token = "abc.abc.abc"
$data = JWT::decode($token, $key, array('HS256'));
Run Code Online (Sandbox Code Playgroud)
要么
$key = "secret";
$token = "abc"
$data = JWT::decode($token, $key, array('HS256'));
Run Code Online (Sandbox Code Playgroud)
PHP将发出异常/错误,如何处理这些异常/错误,以便最终用户不会看到它们(与错误中的我的密钥一起).
我试过做以下事情:
try {
$key = "secret";
$token = "abc"
$data = JWT::decode($token, $key, array('HS256'));
} catch (Exception $e) { // Also tried JwtException
echo 'error';
}
Run Code Online (Sandbox Code Playgroud) 我有一个带有背景图像的div,我想要做的是,当我将鼠标悬停在它上面时,背景图像的隐藏部分将显示如下例所示:
我的jsfiddle例子:
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
background-size: cover;
width: 70px;
height: 70px;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
}
.test:hover{
transform: scale(1.2);
}
body {
text-align: center;
}Run Code Online (Sandbox Code Playgroud)
<div class="test">
</div>Run Code Online (Sandbox Code Playgroud)
正如您所看到的,在我的示例中,图像变得越来越大,而我想要显示另外20px的图像(不会影响边界半径).
我现在正在使用中间件,我现在关注的是:
中间件可以在控制器之前运行,但是在控制器向用户发出响应之前是否可以运行中间件?
我想在执行控制器后设置一些标题.
谢谢
我有以下列表:
[['Andorra', '19165'], ['Algeria', '233724']]
Run Code Online (Sandbox Code Playgroud)
每个子列表中的第一个值是 - country
每个子列表中的第二个值是 - population
如何在此列表中创建字典,该字典将为子列表中的每个值设置country键和population键.
我期待这个结果:
{'Country': 'Andora', 'population': '19165'}, ....
Run Code Online (Sandbox Code Playgroud) 我有以下数组:
var config = {
default: {
username: 'bye',
password: '123',
tries: 3
},
custom: {
username: 'hello',
tries: 2
}
};
Run Code Online (Sandbox Code Playgroud)
我需要从中得到以下结果:
var config = {
username: 'hello',
password: '123',
tries: 2
};
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有以下词典:
[{'country': 'Armenia', 'population': '3026048'}, {'country': 'Angola', 'population': '25830958'}, {'country': 'Algeria', 'population': '40375954'}, {'country': 'Andorra', 'population': '69165'}, {'country': 'Anguilla', 'population': '14763'}, {'country': 'American Samoa', 'population': '55602'}, {'country': 'Aruba', 'population': '104263'}, {'country': 'Argentina', 'population': '43847277'}, {'country': 'Afghanistan', 'population': '33369945'}, {'country': 'Azerbaijan', 'population': '9868447'}, {'country': 'Australia', 'population': '24309330'}, {'country': 'Antigua and Barbuda', 'population': '92738'}, {'country': 'Albania', 'population': '2903700'}, {'country': 'Austria', 'population': '8569633'}]
Run Code Online (Sandbox Code Playgroud)
和以下列表
[['Andorra', '69165'], ['Afghanistan', '33369945'], ['Algeria', '40375954'], ['American Samoa', '55602'], ['Aruba', '104263'], ['Armenia', '3026048'], ['Angola', '25830958'], ['Azerbaijan', '9868447'], ['Antigua and …Run Code Online (Sandbox Code Playgroud)