小编mrm*_*mar的帖子

docker中连接mongoexpress服务出现问题

我有一个启动 nginx 服务器的 docker 配置。现在我必须运行 mongo 和 mongo-express 才能连接到我的数据库。当我将这两个配置放入 docker-compose.yml 并尝试 docker compose up 时,mongo 服务启动,但 mongo express 显示此错误

Could not connect to database using connectionString: mongodb://root:pass@mongodb:27017/" mongo-express_1 | (node:8) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mongodb:27017] on first connect
Run Code Online (Sandbox Code Playgroud)

感谢任何帮助,这是我的配置。

docker-compose.yml

version: "3"

services:
app:
  build:
    context: .
    dockerfile: Dockerfile
  image: cryptoterminal
  container_name: app
  restart: unless-stopped
  volumes:
    - ./:/var/www

webserver:
  build:
    context: .
    dockerfile: Dockerfile_Nginx
  image: nginx
  container_name: webserver
  restart: unless-stopped
  ports:
    - "8080:80"
  volumes: 
    - ./:/var/www
    - …
Run Code Online (Sandbox Code Playgroud)

mongodb docker dockerfile docker-compose mongo-express

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

如何在 Laravel 中数据库种子 JSON 字段?

我无法从 JSON 类型的用户表中播种 user_preference 列。当我输入 .git bash 时,我在 git bash 中收到错误“数组到字符串转换” php artisan db:seed

UserSeeder.php

public function run()
{
    $faker = Faker\Factory::create();
    foreach ($this->getUsers() as $userObject) {
        $user = DB::table('users')->insertGetId([
            "first_name" => $userObject->first_name,
            "last_name" => $userObject->last_name,
            "email" => $userObject->email,
            "email_verified_at" => Carbon::now(),
            "password" => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
            "city" => 'Beograd',

            'user_preferences' => [
                $faker->randomElement(["house", "flat", "apartment", "room", "shop", "lot", "garage"])
            ],

            "created_at" => Carbon::now(),
            "updated_at" => Carbon::now(),
            "type" => 'personal',
        ]);
}
Run Code Online (Sandbox Code Playgroud)

用户表

Schema::table('users', function (Blueprint $table) {
    $table->json('user_preferences')->nullable()->after('city');
});
Run Code Online (Sandbox Code Playgroud)

用户模型 …

php json laravel

7
推荐指数
2
解决办法
5691
查看次数

如何检查密钥是否存在于Redis中?

我在 Laravel 模型中有一个函数,我需要检查我的密钥($key 变量)是否存在于 Redis 中,换句话说,我想创建一个条件,不允许来自 redis 的重复结果。这是我的功能。任何帮助表示赞赏。

功能

public static function cacheFields($fields)
{
    foreach ($fields as $fieldname => $values) {

        $key = static::$redisFieldKey.$fieldname; // here is that variable

        Redis::pipeline(function ($pipe) use ($key, $values) {
            foreach ($values as $value => $label) {
                $pipe->hset($key, $value, $label);
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

php redis laravel

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

如何将文件从主分支推送到另一个分支?

我对使用 git 相当陌生,所以我需要将文件从 master 分支推送到另一个分支,以便在出现问题时进行备份,然后继续在 master 分支上工作。我如何在 git bash 中做到这一点?

git git-bash git-branch

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

如何在 Laravel 的搜索表单上将获取参数作为漂亮的 URL 发送?

我有搜索表单,可以通过特定条件(城市、价格、正交、属性类型)列出属性/广告。例如,我正在尝试获得这样的漂亮网址

project/search/city/London/price/1_10000/quadrature/1_150/propertyType/flat 
Run Code Online (Sandbox Code Playgroud)

而不是像现在这样

project/filter?_token=mCwLL58vOxGHtxEBmntPPcks7nV9n3DHXCNKt7hE&city=London&min_price=1&max_price=10000&min_quadrature=1&max_quadrature=150&propertyType=flat&submit=
Run Code Online (Sandbox Code Playgroud)

这是我第一次做这样的事情,我在 Laravel 中相对较新。我尝试使用 javascript 的 onsubmit 函数来重写 URL,但这没有用,我也用谷歌搜索并尝试创建一个表单操作方法,然后读取查询字符串并重定向到一个带有漂亮 url 的字符串,但我失败了。任何帮助是极大的赞赏。这是我的一些代码,但它显然不起作用:

网页.php

Route::get('/search', 'CategoryController@index');
Route::get('/filter', 'CategoryController@filter');
Run Code Online (Sandbox Code Playgroud)

类别控制器.php

<?php
namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class CategoryController extends Controller
{
public function index()
    {
    $data = \DB::table('properties');
    return view('categories.search', compact('data'));
    }

    public function filter(Request $request)
    {
        $data = \DB::table('properties');

        if ($request->city) {
        $data = $data->where('city', 'LIKE', "%" . $request->city . "%");
        }

        if ($request->min_price && $request->max_price ) {
            $data = $data->where('price', '>=', $request->min_price)
                     ->where('price', '<=', $request->max_price); …
Run Code Online (Sandbox Code Playgroud)

php routes pretty-urls laravel

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