在 Laravel 8 中,我可以使用工厂为用户生成虚拟数据,但我无法为产品生成数据。我收到以下错误:
error BadMethodCallException with message 'Call to undefined method App\Models\Product::factory()'. User_id in Product is the foreign key.
Run Code Online (Sandbox Code Playgroud)
我无法确定出了什么问题。
型号:Product.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
//use HasFactory;
protected $fillable = ['title', 'type', 'firstname', 'surname', 'price', 'papl'];
public function user(){
return $this->belongsTo(User::class);
}
}
Run Code Online (Sandbox Code Playgroud)
型号:User.php
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use HasFactory, Notifiable;
/**
* The attributes that are …Run Code Online (Sandbox Code Playgroud) 我在通过 SSH 推送到我的 Gitlab 帐户时遇到问题,因为我将密钥对移到了不同的文件夹中。
因此,在推入远程后,我收到了“访问被拒绝”错误,我认为这与 ssh 尝试在 .ssh 文件夹中使用标准 id_rsa 的事实有关。
在这里,我找到了一种使用 SSH 私钥的非标准路径来克隆存储库的方法。现在我想使用(来自Git-scm)将其设置为给定存储库的默认值:
git config core.sshCommand='ssh -i path/to/the/key/privatkeyfilename'
Run Code Online (Sandbox Code Playgroud)
我得到并错误:
invalid key: core.sshCommand=ssh -i path/to/the/key/privatkeyfilename
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么?如何实现这一目标?
有谁知道如何从状态通道获取所有连接的用户?我的 API 控制器中需要它们,并将它们全部保存在数据库中。
我发现有些人使用Pusher::get(),但后来我收到一条错误消息Non-static method Pusher\Pusher::get() should not be called statically。我见过其他人使用$this->pusher('/channels'),但是我从哪里获取 $pusher 实例?
抱歉,也许是个菜鸟问题?
我已将 PHP 版本从 7.2 升级到 7.4,发现所有项目的调试都已停止。
我的配置是-
zend_extension="/usr/lib/php/20190902/xdebug.so"
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_log = /tmp/xdebug_remote.log
xdebug.remote_mode = req
xdebug.remote_port = 9000
Run Code Online (Sandbox Code Playgroud)
我已在以下文件中添加了上述配置 -
php -v 命令返回以下输出-
PHP 7.4.14 (cli) (built: Jan 13 2021 08:04:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.14, Copyright (c), by Zend Technologies
with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans
Run Code Online (Sandbox Code Playgroud)
我也在 …