Laravel 6 在 phpunit.xml 中包含了一些额外的配置:
<server name="APP_CONFIG_CACHE" value="bootstrap/cache/config.phpunit.php"/>
<server name="APP_SERVICES_CACHE" value="bootstrap/cache/services.phpunit.php"/>
<server name="APP_PACKAGES_CACHE" value="bootstrap/cache/packages.phpunit.php"/>
<server name="APP_ROUTES_CACHE" value="bootstrap/cache/routes.phpunit.php"/>
<server name="APP_EVENTS_CACHE" value="bootstrap/cache/events.phpunit.php"/>
Run Code Online (Sandbox Code Playgroud)
如果我在 PHPStorm 中运行测试,我会收到以下错误:
在 PackageManifest.php 第 168 行:
bootstrap/cache 目录必须存在且可写。
但是 bootstrap/cache 目录确实存在且可写。但是,如果我在 phpunit.xml 中注释掉这些新配置,我的测试运行时不会出现任何错误。我该如何解决?
我也跑了php artisan cache:clear。没运气。
注销时出现错误,它向我显示此错误...“此路由不支持 GET 方法。支持的方法:POST。” 请帮我解决这个问题..
这是我的代码...
@if(Auth::check())
<li><i class="fa fa-user"></i> {{Auth::user()->name}}:
<a href="{{url('logout')}}">logout</a>
</li>
@else
<li>
<a href="{{route('login')}}"><i class="fa fa-user"></i>Login</a>
</li>
@endif
Run Code Online (Sandbox Code Playgroud) 我在 Laravel 中有一个更高阶的消息。它看起来像这样:
$category->scores->each->ratings->where('result.rating', '>=', 3)->count();
Run Code Online (Sandbox Code Playgroud)
Acategory有scores一个scorehasratings和 arating有一个result。
我想获得每个类别 的评分总数where >= 3。
使用我现在拥有的代码,最终结果始终为 0。
但是当我像这样循环时:
@foreach($categories as $category)
@foreach($category->scores as $score)
@foreach($score->ratings->where('result.rating', '>=', 3) as $rating)
{{ $rating->result->result_nl }}
@endforeach
@endforeach
@endforeach
Run Code Online (Sandbox Code Playgroud)
有3个评分结果。
我的高阶消息有什么问题?
这可能是一个非常新手的问题,但是,您到底如何使用 phpDocumentor 通过 Laravel 生成文档?在我的 Laravel 项目中,目录中没有phpdocvendor/bin,并且尝试通过 Composer 安装 phpDocumentor 失败(如 GitHub 页面上的建议)。
我找不到任何有关它的最新资源,我唯一幸运的是phpDocumentor.phar从终端运行该文件,但最新版本立即失败。
我尝试在 Debian 9 终端上安装 Laravel with Composer
composer global require laravel/installer
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Using version ^3.0 for laravel/installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- laravel/installer v3.0.1 requires ext-zip * -> the requested PHP extension zip is missing from your system.
- laravel/installer v3.0.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
- …Run Code Online (Sandbox Code Playgroud) 我有一个使用访问器和修改器来加密模型值的特性:
trait Encryptable
{
public function getAttribute($key)
{
$value = parent::getAttribute($key);
if (in_array($key, $this->encryptable)) {
$value = Crypt::decrypt($value);
return $value;
} else {
return $value;
}
}
public function setAttribute($key, $value)
{
if (in_array($key, $this->encryptable)) {
$value = Crypt::encrypt($value);
}
return parent::setAttribute($key, $value);
}
}
Run Code Online (Sandbox Code Playgroud)
评论模型
protected $fillable = ['content','user_id','commentable_id', 'commentable_type'];
protected $encryptable = [
'content'
];
Run Code Online (Sandbox Code Playgroud)
评论控制器
public function storePostComment(Request $request, Post $Post)
{
$this->validate($request, [
'content' => 'required',
]);
$comment = $post->comments()->create([
'user_id' => auth()->user()->id,
'content' => $request->content …Run Code Online (Sandbox Code Playgroud) $ composer create-project --prefer-dist laravel/laravel="5.8.*" larastart
Run Code Online (Sandbox Code Playgroud)
它不起作用,我也尝试了其他一些方法,但对我不起作用
这是我得到的错误:
内容长度不匹配,收到 188377 字节超出预期 620920 repo.packagist.org 无法完全加载,包信息已从本地缓存加载,可能已过期
OS Name Microsoft Windows 10 Home Single Language
Version 10.0.18363 Build 18363
Other OS Description Not Available
OS Manufacturer Microsoft Corporation
System Name DESKTOP-7CV9HTK
System Manufacturer HP
System Model HP ENVY Laptop 13-ah1xxx
System Type x64-based PC
System SKU 5HZ05PA#AKL
Processor Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz, 1992 Mhz, 4 Core(s), 8 Logical Processor(s)
BIOS Version/Date Insyde F.12, 11/8/2018
SMBIOS Version 3.0
Embedded Controller Version 69.72 …Run Code Online (Sandbox Code Playgroud) 我一直在尝试access_token为我的 api创建一个。我遵循了设置并使用 Postman 来测试/创建令牌。我似乎无法克服invalid_grant错误。
我已经尝试了我能找到的所有组合,但没有任何运气。这是我的设置:
发送POST请求至:http://mywebsite.local/oauth/token
在正文中,我设置form-data为这个(名称/值):
grant_type password
client_id 1
client_secret <super_long_string>
username my@email.com
password secret
Run Code Online (Sandbox Code Playgroud)
我使用 tinker 创建了一个虚拟用户:
factory('App\User')->create()
Run Code Online (Sandbox Code Playgroud)
我在上面使用新创建的用户作为我的用户名/密码。
不管我在做什么(没有传递任何东西),这是我总是看到的错误:
{
"error": "invalid_grant",
"error_description": "The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.",
"hint": "",
"message": "The provided authorization grant (e.g., …Run Code Online (Sandbox Code Playgroud) 我的框架是 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) 我的问题是:
被该time()[10位数(秒)]可提高到11个或12位数字?
问这个问题的目的是我正在创建一个 uniq 交易 id 取决于它和其他一些变量..我必须保持 18 位数字的长度(仅限数字)
编辑:注意我不想让它更长.. 当它增加到 11/12 位时,我必须动态地使其余的 7/8 位.. 因为我在最后 7/8 位使用了 2 个随机发生器
EDIT2:它才有意义=> rand(8 Digits)VS rand(3)+ rand(3)+rand(2)碰撞目的?
laravel ×10
laravel-6 ×10
php ×5
laravel-5.7 ×2
laravel-5.8 ×2
accessor ×1
debian ×1
eloquent ×1
encryption ×1
laravel-7 ×1
phpdoc ×1
phpunit ×1
routes ×1
unique ×1