标签: laravel-7

有没有正确的方法将 Trix 编辑器与 Livewire 连接起来?

将 Trix 编辑器内容与 Livewire 连接在一起时,我遇到了问题。我认为问题在于当 Livewire 从 Trix 接收内容时,内容会被换出并且 Trix 被禁用。有没有更好的办法?

我所做的,有效的,如下。目前,页面被重定向到自身以重新启动 Trix(击败了 Livewire 的全部要点,但它也被用于其他事情)。

<div>
  <input
      id="newCommentTextTrixContent"
      type="hidden"
      wire:model="newCommentText"
  >

  <trix-editor
      id="newCommentTextTrixEditor"
      input="newCommentTextTrixContent"
  ></trix-editor>


  <button wire:click="addComment(document.getElementById('newCommentTextTrixEditor').innerHTML)">Add Comment</button>
</div>
Run Code Online (Sandbox Code Playgroud)

我试过了

  • 隐藏输入上的线:模型 - 没有任何反应
  • x-on:trix-change="$set('comment', $event.target.innerHTML) -- 这有效,但 Trix 在第一次按键后变灰并停止工作(重启问题?)

我敢肯定像后者这样的东西更好,但是每次都以某种方式重新启动 Trix。这一切似乎有点混乱 - 所以问题是,这样做的正确方法是什么?

trix laravel-livewire alpine.js laravel-7

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

Laravel 7.1.x 缺少文件:AuthenticatesUsers、RegistersUsers

我刚刚从 Laravel 6.x 升级到 7.1.x,现在我的应用程序由于更改而搞砸了。其中之一是登录身份验证。

在新的 Laravel 7.1.2 中,这些文件消失了。

  1. 使用 Illuminate\Foundation\Auth\RegistersUsers;
  2. 使用 Illuminate\Foundation\Auth\AuthenticatesUsers;

如果您要查看API 文档,这些文件也会丢失。有了这个,我可以知道它们被替换为哪些文件吗?

laravel laravel-7

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

为什么 Cache::lock() 在 Laravel 7 中返回 false?

我的框架是 Laravel 7,缓存驱动程序是 Memcached。我想执行原子缓存获取/编辑/放置。为此我使用Cache::lock()但它似乎不起作用。返回$lock->get()false(见下文)。我该如何解决这个问题?

Fort 测试,我重新加载 Homestead,并仅运行下面的代码。并且锁定永远不会发生。是否有可能Cache::has()破坏锁定机制?

if (Cache::store('memcached')->has('post_' . $post_id)) {
    $lock = Cache::lock('post_' . $post_id, 10);
    Log::info('checkpoint 1'); // comes here

    if ($lock->get()) {
        Log::info('checkpoint 2'); // but not here.
        $post_data = Cache::store('memcached')->get('post_' . $post_id);
        ... // updating $post_data..
        Cache::put('post_' . $post_id, $post_data, 5 * 60);
        $lock->release();
    }
} else {
        Cache::store('memcached')->put('post_' . $post_id, $initial, 5 * 60);
}
Run Code Online (Sandbox Code Playgroud)

laravel laravel-6 laravel-7

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

Animate.css 似乎不适用于 Chrome 和 FF 中的 Laravel 7.10.3

我正在尝试在 Laravel 项目中使用Animate.css 。我使用以下命令安装了 Animate.css:

npm install animate.css --save
Run Code Online (Sandbox Code Playgroud)

我将其包含在 \resources\sass\app.scss 文件中:

@import "~animate.css/animate.css";
Run Code Online (Sandbox Code Playgroud)

然后我运行以下 npm 命令将其编译为 app.css:

npm run dev
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中查看页面源代码时,似乎包含 animate.css 但 HTML 元素没有动画。动画似乎可以在 Edge 中运行,但不能在 Chrome (v81.0.4044.138) 或 FF (v76.0) 中运行。

laravel animate.css laravel-7

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

如何在浏览器窗口关闭时更新数据库?

我正在尝试将一些视频流式传输给用户,并且我想让他们在离开网站并再次进入时能够继续观看视频。据我所知,将视频时间存储在浏览器的本地存储中并在返回时检索它是最好的方法,但在这种情况下,当用户从不同的 PC 或浏览器登录时,视频观看时间会重置。由于现在在某些浏览器中禁用了同步 Ajax,我也无法在浏览器关闭(使用onunloadbeforeunload事件)时将观看时间保存在数据库中。

我尝试过的另一种方法是节省用户点击暂停按钮的时间,如下所示:

var video1 = document.getElementById('video1');

function videoPausePlayHandler(e) {
    if (e.type == 'pause') {
        //saving the watched time in databse using Ajax
    }
}
video1.addEventListener('pause', videoPausePlayHandler, false);
Run Code Online (Sandbox Code Playgroud)

但是,当用户关闭浏览器窗口或其他任何东西而不是单击暂停按钮时,它将不起作用。

有没有其他方法可以做到这一点?

javascript jquery laravel-7

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

无法解决依赖关系 - Laravel

Illuminate\Contracts\Container\BindingResolutionException 无法解析 App\Jobs\BudgetFetch 类中的依赖关系 [参数 #0 [ $customerId ]]

namespace App\Http\Controllers;
use App\Jobs\BudgetFetch;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\Lib\V3\GoogleAdsClientBuilder;
use Illuminate\Support\Facades\DB;

class APIController extends Controller
{
    public function index() {
        $clients = DB::table('account_names')->pluck('code');

        foreach($clients as $customerId) {
            budgetFetch::dispatch($customerId);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

上面是一个简单的控制器,我将其组合在一起以触发另一项工作:

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\Lib\V3\GoogleAdsClientBuilder;

class BudgetFetch implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function …
Run Code Online (Sandbox Code Playgroud)

laravel google-ads-api laravel-7

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

如何修复 Laravel 迁移中的外键错误

我有一个订单表,我之前创建了这个表,但一段时间后我必须更改我的迁移。

这是更改前我的订单表:

Schema::create('orders', function (Blueprint $table) {
        $table->id();

        $table->unsignedBigInteger('user_id');
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

        $table->bigInteger('price');
        $table->enum('status', ['unpaid', 'paid', 'preparation', 'posted', 'recieved', 'canceled']);
        $table->string('tracking_serial')->nullable();

        $table->timestamps();
    });

    Schema::create('order_product', function (Blueprint $table) {
        $table->unsignedBigInteger('product_id');
        $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');

        $table->unsignedBigInteger('order_id');
        $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');

        $table->integer('quantity');

        $table->primary(['product_id', 'order_id']);
    });
Run Code Online (Sandbox Code Playgroud)

这是更改后的订单表

Schema::create('orders', function (Blueprint $table) {
        $table->id();

        $table->unsignedBigInteger('user_id');
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

        $table->unsignedBigInteger('address_id');
        $table->foreign('address_id')->references('id')->on('addresses')->onDelete('cascade');

        $table->bigInteger('price');
        $table->string('post_type');
        $table->enum('status', ['unpaid', 'paid', 'preparation', 'posted', 'recieved', 'canceled']);
        $table->string('tracking_serial')->nullable();

        $table->primary(['user_id', 'address_id']);

        $table->timestamps();
    });

    Schema::create('order_product', function (Blueprint $table) {
        $table->unsignedBigInteger('product_id');
        $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');

        $table->unsignedBigInteger('order_id');
        $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');

        $table->integer('quantity');

        $table->primary(['product_id', 'order_id']);
    });
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我在ordersschema 中导入了 3 …

php migration migrate laravel laravel-7

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

Laravel 7:为什么我的会话 cookie 没有在浏览器中设置?

即使服务器响应包含正确的Set-Cookie标头,我的 Laravel 会话 cookie 也不会在浏览器中设置。Laravel 服务器运行在 localhost:8000,客户端应用程序是一个运行在 localhost:7000 的 NuxtJS SPA。

包含的响应头Set-Cookie如下:

HTTP/1.1 200 OK
Host: localhost:8000
Date: Sun, 06 Sep 2020 00:50:31 GMT
Connection: close
X-Powered-By: PHP/7.4.10
Cache-Control: no-cache, private
Date: Sun, 06 Sep 2020 00:50:31 GMT
Content-Type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, PATCH, DELETE
Access-Control-Allow-Headers: Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Authorization, Access-Control-Request-Headers, Set-Cookie
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 59
Set-Cookie: dv_session=ifhSq8WFD2Upltr5v2bzNBgaA5xx3KiDVuMWuBge; expires=Sun, 06-Sep-2020 02:50:31 GMT; Max-Age=7200; path=/
Run Code Online (Sandbox Code Playgroud)

通过邮递员发出相同的请求,cookie被保存:

在此处输入图片说明

因此,浏览器似乎忽略了“Set-Cookie”标头。

我的 session.php 文件如下: …

php cookies laravel laravel-7

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

Laravel 8 创建后的出厂状态

Laravel 7 工厂有afterCreatingState()方法,您可以在其中定义具有特定状态的模型保存到数据库后应该发生的事情。

$factory->afterCreatingState(App\User::class, 'active', function ($user, $faker) {
    // ...
});
Run Code Online (Sandbox Code Playgroud)

Laravel 8 工厂没有这个方法,而是只有通用afterCreating()

public function configure()
{
    return $this->afterCreating(function (User $user) {
        //
    });
}
Run Code Online (Sandbox Code Playgroud)

如何实现这种行为?

php laravel laravel-7 laravel-8

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

目标类[视图]不存在。在Container.php中

我的 laravel 有问题,暂时不知道如何解决。实际上我不知道我如何面对这个问题,但我会尽力向你解释我做了什么以及我现在尝试了什么来解决这个问题。

我尝试了一下 composer update,出现了这个问题。现在我无法键入任何命令,例如php artisan make:livewire name 或什至php artisan --version,每次当我尝试执行命令时,我都会在控制台中收到此错误

In Container.php line 811:
                                       
  Target class [view] does not exist.  
                                       

In Container.php line 809:
                             
  Class view does not exist 

Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1 
                             
Run Code Online (Sandbox Code Playgroud)

还有日志文件中的信息

[previous exception] [object] (ReflectionException(code: -1): Class view does not exist at /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php:809)
[stacktrace]
#0 /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(809): ReflectionClass->__construct()
#1 /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(691): Illuminate\\Container\\Container->build()
#2 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(796): Illuminate\\Container\\Container->resolve()
#3 /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(637): Illuminate\\Foundation\\Application->resolve()
#4 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(781): Illuminate\\Container\\Container->make()
#5 /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(1284): …
Run Code Online (Sandbox Code Playgroud)

php laravel composer-php laravel-7

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