小编Kai*_*all的帖子

确定JavaScript值是否为"整数"?

可能重复:
检查变量是否包含Javascript中的数值?

如何在jQuery中检查变量是否为整数?

例:

if (id == int) { // Do this }
Run Code Online (Sandbox Code Playgroud)

我使用以下内容从URL获取ID.

var id = $.getURLParam("id");
Run Code Online (Sandbox Code Playgroud)

但我想检查变量是否是整数.

javascript jquery

76
推荐指数
3
解决办法
11万
查看次数

Laravel雄辩,其中日期等于或大于DateTime

我正在尝试从日期列高于或等于当前时间的模型中获取关系数据.

日期列格式如下:Ymd H:i:s

我想要做的是抓住Ymd H:i:s未来的所有行.

示例:假设日期为2017-06-01,时间为09:00:00然后我希望获得日期为将来的所有行,时间是将来的.

目前我的代码看起来像这样,它几乎正常工作,但它没有抓住日期是当天的行.

public function customerCardFollowups() {
    return $this -> hasMany('App\CustomerCardFollowup', 'user_id') -> whereDate('date', '>', Carbon::now('Europe/Stockholm')) -> orderBy('date', 'asc') -> take(20);
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?提前致谢.

php mysql datetime laravel eloquent

12
推荐指数
3
解决办法
4万
查看次数

Laravel excel 在导入前获取总行数

直截了当的问题。如何使用 laravel-excel 获取电子表格中的总行数?

我现在有一个工作计数器,用于记录已处理的行数(在文件中CompanyImport),但在开始将行添加到数据库之前我需要总行数。

我正在导入的工作表几乎有 100 万行,因此我尝试创建一个进度条。

我的进口:

public function model(array $row)
{
    # Counter
    ++$this->currentRow;

    # Dont create or validate on empty rows
    # Bad workaround
    # TODO: better solution
    if (!array_filter($row)) {
        return null;
    }

    # Create company
    $company = new Company;
    $company->crn = $row['crn'];
    $company->name = $row['name'];
    $company->email = $row['email'];
    $company->phone = $row['phone'];
    $company->website = (!empty($row['website'])) ? Helper::addScheme($row['website']) : '';
    $company->save();

    # Everything empty.. delete address
    if (!empty($row['country']) || !empty($row['state']) || !empty($row['postal']) || !empty($row['address']) || …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-excel

8
推荐指数
2
解决办法
3万
查看次数

Canvas onClick添加到数组

我得到了这个我正在努力的HTML5画布项目.基本上我正在尝试在点击时添加新粒子.并且粒子被推到粒子阵列,但粒子没有显示出来.我可以看到粒子被鼠标坐标推到了数组,但看起来并不是最后一个粒子被绘制出来的.我究竟做错了什么?

见例子.

// Request animation frame
var requestAnimationFrame = window.requestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.msRequestAnimationFrame;

// Canvas
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');

// Set full-screen
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

// Options
var num = 100;              // Number of particles to draw
var size = 2;               // Particle size
var color = '#dd64e6';      // Particle color
var min_speed = .3;         // Particle min speed
var max_speed = 2;          // Particle max speed
var dist = …
Run Code Online (Sandbox Code Playgroud)

javascript arrays html5 animation canvas

6
推荐指数
1
解决办法
194
查看次数

PHP MVC结构放置自己的类

我刚开始看一下MVC模式.我的问题是:

我将把我的其他类文件(数据库,用户,记录器,邮件程序等)放在哪里?我应该为他们创建一个新目录libs吗?

我应该Controllermodel函数内部实例化类吗?

<?php

class Controller {
    protected function model($model) {
        require_once('../app/models/'. $model .'.php');

        return new $model();
    }

    protected function view($view, $data = []) {
        require_once '../app/views/'. $view .'.php';
    }
}
Run Code Online (Sandbox Code Playgroud)

php model-view-controller structure

5
推荐指数
1
解决办法
997
查看次数

如果id相同,Laravel验证唯一

我有一个表/模型,每个用户包含多个相册.有没有办法说该列title应该是唯一的,但只适用于具有相同的行user_id

示例:http://pastebin.com/8dvM4a1T

正如您在示例中所看到的,ID为2的用户创建了2个具有相同标题的专辑.我不希望这被允许,这就是为什么我想知道是否有办法用Laravel的验证器否认这一点?

我试过这个,但那没用.

// Validator
    $validator = Validator::make($input, [
        'title' => 'required|min:1|max:255|unique:galleries,title,'. Auth::user() -> id .',user_id',
        'description' => 'min:1|max:255'
    ]);
Run Code Online (Sandbox Code Playgroud)

任何帮助表示感谢,谢谢.

php mysql validation laravel

5
推荐指数
2
解决办法
4894
查看次数

HTML5画布粒子爆炸

我正试图让粒子爆炸起作用.它工作,但看起来有些帧不会被渲染.如果我多次点击几次爆炸就会开始呃......"滞后/断断续续".有什么我忘记做的事吗?当我点击多次时,浏览器可能会挂起.在彼此内部有2个循环是不是太多了?

附上我的代码,你可以看到.只需尝试多次点击,您就会看到问题.

// Request animation frame
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
// Canvas
var c = document.getElementById('canvas');
var ctx = c.getContext('2d');
// Set full-screen
c.width = window.innerWidth;
c.height = window.innerHeight;
// Options
var background = '#333'; // Background color
var particlesPerExplosion = 20;
var particlesMinSpeed = 3;
var particlesMaxSpeed = 6;
var particlesMinSize = 1;
var particlesMaxSize = 3;
var explosions = [];
var fps = 60;
var now, delta;
var then = Date.now();
var …
Run Code Online (Sandbox Code Playgroud)

javascript html5 canvas

5
推荐指数
1
解决办法
2273
查看次数

PHP:如何检查数据库中的ID是否存在

如果表中不存在ID,为什么不将用户发送到user.php?

<?php
include 'db_connect.php';
$id_exists = false;
$url_id = mysql_real_escape_string($_GET['id']);
$sql = "SELECT id FROM members WHERE id='$url_id'";
$result = mysql_query($sql);

if ($result == $url_id)
{
        $id_exists = true;
}

else if ($result != $url_id)
{
        $id_exists = false;
        header("location:user.php");
        exit();
}

?> 
Run Code Online (Sandbox Code Playgroud)

Thx提前!

php mysql get

4
推荐指数
1
解决办法
3万
查看次数

SwiftMailer 测试用户名和密码

我真的不知道这是关于SwiftMailer还是mailtrap.io,但问题是当我尝试建立到所述服务(mailtrap.io)的 SMTP 连接时,即使我不使用任何用户名或密码,我也从未收到任何错误。不使用任何用户名或密码时,我不应该收到任何身份验证错误吗?或者我这样做的方式不对?

这是我在将其存储到文件之前测试是否可以建立动态连接的方法.env

/**
 * E-mail configuration
 *
 * @param Request $request
 * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
 */
public function postEmailConfiguration(Request $request)
{
    # Try connecting to the SMTP
    try {

        $encryption = $request->input('encryption');
        if ($encryption == 'null') {
            $encryption = NULL;
        }

        $transport = new Swift_SmtpTransport($request->input('host'), $request->input('port'), $encryption);
        $transport->setUsername($request->input('username'));
        $transport->setPassword($request->input('password'));

        $mailer = new Swift_Mailer($transport);
        $mailer->getTransport()->start();

        # Update .env file
        $this->setEnvironmentValues([
            'MAIL_HOST' => $request->input('host'),
            'MAIL_PORT' => $request->input('port'),
            'MAIL_USERNAME' => $request->input('username'),
            'MAIL_PASSWORD' => $request->input('password'), …
Run Code Online (Sandbox Code Playgroud)

php email swiftmailer laravel

4
推荐指数
1
解决办法
2638
查看次数

Axios 错误:....data.pipe 不是函数

所以我基本上尝试使用 axios 从 url 下载图像,但出现此错误:

TypeError: streamResponse.data.pipe is not a function

我执行此图像下载的函数如下(请注意,这是在一个类中):

/**
 * Download poster
 */
async downloadPoster() {

    // Writer stream where we want to download the poster image
    const writer = fs.createWriteStream(this.poster.file);

    // This grabs the second part of the image url that we want
    const resultsResponse = await axios({
        url: this.poster.url,
        method: 'GET',
        responseType: 'json',
        adapter: httpAdapter
    });

    // Zero results
    if (resultsResponse.data.total_results <= 0) {
        logger.log(language[Config.language].posterNotFound + this.movie.title, 'error');
        return false;
    }

    // …
Run Code Online (Sandbox Code Playgroud)

javascript node.js axios

4
推荐指数
1
解决办法
1万
查看次数