小编Men*_*ena的帖子

无法解析项目:CordovaLib

我正在学习如何使用cordova构建应用程序,我现在可以通过谷歌浏览器模拟移动屏幕.我试图在android平台上测试它,这需要使用Android studio(下载3.0稳定版).导入项目后,Gradle项目同步失败,似乎存在解决CordovaLib的某些依赖项的问题.见下图

在此输入图像描述

我在这里经历了几篇文章但仍然无法找到解决方案,或者考虑到这是我第一次用它学习,我可能会错过这一点.以下是设置

build.gradle(模块:CordovaLib)

在此输入图像描述

和build.gradle(模块:android)

在此输入图像描述

请问如何解决问题并在模拟器中运行我的应用程序?

android cordova android-studio

11
推荐指数
1
解决办法
7615
查看次数

ERR_INVALID_ARG_TYPE错误

我在学习 Angular 2 时从 API 获取数据时遇到问题。这是我收到的错误

url.js:106 抛出新错误。TypeError('ERR_INVALID_ARG_TYPE', 'url', 'string', url); 类型错误 [ERR_INVALID_ARG_TYPE]:“url”参数必须是字符串类型。在 Url.parse 处接收到的类型未定义 (url.js:106:11)

这是我正在使用的代码

索引.js

const express = require('express');
const app = express();

const MongoClient = require('mongodb').MongoClient;

require('dotenv').config();

let database;

MongoClient.connect(process.env.DB_CONN, (err, db) => {

console.log('connected to mongodb...');

app.listen(3000, () => {
    database = db;
    console.log('listening on port 3000...')
});
});

app.get('/contacts', (req, res) => {
const contactsCollection = database.collection('contacts');

contactsCollection.find({}).toArray((err, docs) => {
    if(err) {
        console.log(err);
    }
    return res.json(docs);
});
});
Run Code Online (Sandbox Code Playgroud)

.env

DB_CONN=mongodb://admin:password@ds117931.mlab.com:17931/dem-contact
Run Code Online (Sandbox Code Playgroud)

我不明白这个错误,因为我使用的是 mlab mongodb,所以我唯一的 …

javascript mongodb angular

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

如何清除 Angular 反应式表单输入值

我有一个像这样设置的简单反应形式

constructor(private scheduleService: ScheduleService, fb: FormBuilder) {
this.searchForm = fb.group({
  from: ["", Validators.required],
  to: ["", Validators.required],
  date: ["", Validators.required]
});
}
Run Code Online (Sandbox Code Playgroud)

我想通过单击调用清除函数的按钮来清除表单字段。我的清除功能目前不起作用,看起来像这样

clear() {
console.log("Reset all search form fields to null.");

this.searchForm.from = "";
this.searchForm.to = "";
this.searchForm.date = "";
}
Run Code Online (Sandbox Code Playgroud)

使用角度反应表单时清除表单输入字段的正确方法是什么?如何通过使用单个语句重置所有表单字段而不是单个字段来实现此目的?

angular angular-reactive-forms

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

该文件超出了Laravel中的upload_max_filesize ini指令(限制为2048 KiB)

尝试上传图像时,在开发环境中遇到上述错误。我通过以下操作遵循了其他答案

  • 设置upload_max_filesize和post_max_size
  • 重启wamp服务器
  • 关闭系统并重新启动系统

但我仍然无法克服错误。我做错什么了吗?以下是我的php.ini文件中的相关部分

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 100M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 125M
Run Code Online (Sandbox Code Playgroud)

php laravel-5.4

3
推荐指数
3
解决办法
8886
查看次数

如何在同一行显示文本和图标

我正在使用 bootstrap 4 和 fontawesome,并希望在同一行上显示文本和图标。文字应该在左上角,而图标在右下角。目前,我无法将文本和图标保持在同一行,图标似乎移动到文本下方的一行。我怎样才能解决这个问题?

<link href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>

<div class="card-header">
      <span class="d-inline">Cars waiting pedestrians cross the street</span>
      <span class="d-inline btn d-flex justify-content-end">
          <i class="fas fa-angle-down"></i>
      </span>
    </div>
Run Code Online (Sandbox Code Playgroud)

bootstrap-4

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

类型错误:无法在 insertOne 的 insertDocuments 中读取未定义的属性“_id”

当抛出此错误时,我试图将记录插入集合中。我浏览了insertOne上的 mongodb 文档,我知道 mongod 会在未指定 _id 时自动添加 _id (如我的情况),所以我想知道为什么会出现未定义的 id 错误。

这是我正在使用的代码,首先是 api 路由和我尝试插入的数据

app.post('/api/contacts', (req, res) => {
// retrieve the user being added in the body of the request
const user = req.body;

// obtain a reference to the contacts collection
const contactsCollection = database.collection('contacts');

// insert data into the collection
contactsCollection.insertOne(user, (err, r) => {
    if (err) {
        return res.status(500).json({error: 'Error inserting new record.'});
    }

    const newRecord = r.ops[0];

    return res.status(201).json(newRecord);
});
});
Run Code Online (Sandbox Code Playgroud)

用于插入的json数据

{ …
Run Code Online (Sandbox Code Playgroud)

mongodb express

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

如何使用 Passport 在 phpunit 测试中验证用户身份

我正在尝试编写一个 PHPUnit 测试,在允许用户发出发布请求之前首先对用户进行身份验证,但出现错误

1)Tests\Feature\BooksTest::test_onlyAuthenticatedUserCanAddBookSuccessively ErrorException:尝试获取非对象的属性“client”

C:\wamp64\www\bookstore\vendor\laravel\passport\src\ClientRepository.php:89 C:\wamp64\www\bookstore\vendor\laravel\passport\src\PersonalAccessTokenFactory.php:71 C:\wamp64\www \bookstore\vendor\laravel\passport\src\HasApiTokens.php:67 C:\wamp64\www\bookstore\tests\Feature\BooksTest.php:20

当我运行 BooksTest 时

public function test_onlyAuthenticatedUserCanAddBookSuccessfully()
{
    $user = factory(User::class)->create();
    $token = $user->createToken('bookbook')->accessToken;

    $response = $this->withHeaders(['Authorization' => 'Bearer '.$token])
        ->json('POST', '/api/books', [
            'title' => 'new book post',
            'author' => 'new author',
            'user_id' => $user->id
        ]);

    $response->assertStatus(201);
}
Run Code Online (Sandbox Code Playgroud)

这是我第一次使用 PHPUnit 测试,我不知道为什么会收到此错误。我该如何让它发挥作用?

php phpunit laravel laravel-5.6

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

调用另一个工厂内的工厂

我目前正在学习如何使用 Laravel 应用程序编写 PHPUnit 测试,但几天来却遇到了困难。我的测试是,如果用户的 id 与图书的用户 id 相同,则仅允许经过身份验证的用户更新图书记录。

public function test_onlyAuthenticatedUserCanUpdateBookSuccessfully()
{
    $user = factory(User::class)->create();
    Passport::actingAs($user);

    $book = factory(Book::class)->create();

    dd($user, $book);

    // $response = $this->json('PUT', '/api/books/'.$book->id, [
    //         'id'    => $book->id,
    //         'title' => 'Updated book title',
    //         'author'=> 'New Guy'
    //     ]);

    // $response->assertStatus(201);
}
Run Code Online (Sandbox Code Playgroud)

但我最初遇到了 403 错误,在排除故障时,我从转储的数据中注意到创建的用户的 id 与书籍的 user_id 不同。

// Newly created user
#original: array:7 [
    "name" => "Prof. Norwood Erdman"
    "email" => "ihoeger@example.com"
    "updated_at" => "2018-10-03 14:11:20"
    "created_at" => "2018-10-03 14:11:20"
    "id" => 2 …
Run Code Online (Sandbox Code Playgroud)

phpunit laravel laravel-5.6

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

在 Laravel API 资源响应中包含关系

我的目标是创建一个具有评级关系的书店 API 端点。Book & Rating的关系是这样的:

书型

/**
* a book has many ratings
*/
public function ratings()
{
    return $this->hasMany(Rating::class, 'book_id')->orderBy('created_at', 'ASC');
}
Run Code Online (Sandbox Code Playgroud)

评级模型

/**
* a rating belongs to a book
*/
public function book()
{
    return $this->belongsTo(Book::class);
}
Run Code Online (Sandbox Code Playgroud)

我的 BookResource 看起来像这样

<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

use App\Http\Resources\RatingResource;

class BookResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        // return parent::toArray($request);
        return …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5.7

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

配置 Swagger UI 路由

我想使用 swagger 来记录 Laravel API 并让用户使用与petstore.swagger.io

swagger-php这是我使用&l5-swagger包所采取的步骤

  1. 作曲家需要 zircote/swagger-php
  2. 作曲家需要 darkaonline/l5-swagger
  3. 添加L5Swagger\L5SwaggerServiceProvider::class,到 config/app.php 文件
  4. 为 BookController 添加注释
  5. 运行命令php artisan l5-swagger:generate

然后我像这样向 BookController 添加注释

/**
 * @OA\Info(
 *      version="1.0.0",
 *      title="Laravel Test OpenApi",
 *      description="L5 Swagger OpenApi description",
 *      @OA\Contact(
 *          email="menadio1@gmail.com"
 *      ),
 *     @OA\License(
 *         name="Apache 2.0",
 *         url="http://www.apache.org/licenses/LICENSE-2.0.html"
 *     )
 * )
 */
/**
 *  @OA\Server(
 *      url=L5_SWAGGER_CONST_HOST,
 *      description="L5 Swagger OpenApi dynamic host server"
 *  )
 *
 *  @OA\Server(
* …
Run Code Online (Sandbox Code Playgroud)

php swagger swagger-php swagger-ui laravel-5.7

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