我刚刚开始学习jest测试并创建了一个示例应用程序来熟悉jest测试。但是,我收到以下错误...
语言.js
const calculateTip = (total, percentage) => {
return total + ((percentage / 100) * total) + 1;
};
export {
calculateTip,
}
Run Code Online (Sandbox Code Playgroud)
包.json
{
"dependencies": {
"express": "^4.18.2"
},
"type": "module",
"main": "src/app.js",
"scripts": {
"start": "node src/app.js",
"test": "cls && env-cmd -f ./envs/test.env jest --watchAll"
},
"devDependencies": {
"env-cmd": "^10.1.0",
"jest": "^29.2.2",
"supertest": "^6.3.1"
}
}
Run Code Online (Sandbox Code Playgroud)
我曾尝试通过谷歌搜索解决方案,但到目前为止还没有运气。
我有一个应用程序,我在其中创建了一个新的守卫residents,它是UserLaravel 附带的默认类的精确副本。但是当我改变守卫时,它开始显示这个错误:
Argument 2 passed to Illuminate\Auth\SessionGuard::__construct() must be an instance of Illuminate\Contracts\Auth\UserProvider, null given, called in ...\vendor\laravel\framework\src\Illuminate\Auth\AuthManager.php on line 125
我尝试使用谷歌搜索解决方案并阅读了很多但没有任何效果。
Laravel 版本是 5.8
身份验证文件
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'residents',
'hash' => false,
],
],
'providers' => [
'residents' => [
'driver' => 'eloquent',
'model' => App\ApiModels\Resident::class,
], …Run Code Online (Sandbox Code Playgroud) 我最近下载了新的Windows Terminal. 我已经创建了打开多个窗格的快捷方式(工作正常)。但是,我正在尝试为相应的窗格执行命令。
wt -d <path> -c "cls && php artisan serve" ;
split-pane -p "Command Prompt" -H -d <path> -c "npm run watch"
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索了解决方案,但没有运气。
这甚至可能..?
在我的 Laravel 应用程序中,我使用了普通路由,例如 GET、POST、PUT 以及所有带有各种控制器的路由。但是随着应用程序的进行,routes/api.php文件变得非常庞大。因此,我正在使用“资源控制器”语法对其进行更改,以实现更简洁和精简的代码。
但是,早些时候我能够使用 url 中的“token”或“slug”参数来获取数据,例如:show/{token} & show($token)或show/{slug} & show($slug ),但现在每当我尝试这些或任何其他参数时,我都会404 not found出错。因此,我只使用默认的“id”参数。
之前:
Route::get('/categories', 'CategoryController@index');
Route::get('/categories/{token}', 'CategoryController@show');
Run Code Online (Sandbox Code Playgroud)
现在:
Route::resource('/categories', 'CategoryController');
Run Code Online (Sandbox Code Playgroud)
有什么方法可以将默认的“id”参数更改为任何其他..?
如果帐户(可能是电子邮件或手机)已通过验证码验证,我希望跳过验证码验证。
所以我写了一个colsure函数。如果session('captcha_validated_reset_account')等于用户输入的帐户,它将跳过验证码验证。
如果没有,程序将调用 laravel 验证规则,如“required|captcha”(captcha'来自https://github.com/mewebstudio/captcha)。
问题是我不知道如何在闭包中调用验证规则,我尝试返回“required|captcha”,但它没有按预期工作。
'captcha' => function($attribute, $val, $fail) use ($request) {
if (
! empty(session('captcha_validated_reset_account'))
&& session('captcha_validated_reset_account') == $request->input('account')
) {
return;
} else {
Rule::required... //and call a rule named 'captcha' to validate the captcha code from user input
//return 'required|captcha';
}
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以在闭包函数中调用 laravel 验证规则吗?
我是Laravel-mix和的新人webpack。经过一些练习,我能够将 css 和 js 文件分别组合成 1 个文件。但是,合并后其他文件仍然存在,对应用程序没有用处。
例如:
resources
|-- scss
|-- font-awesome.scss
|-- template.scss
public
|-- css
|-- font-awesome.css
|-- template.css
Run Code Online (Sandbox Code Playgroud)
合并后:
public
|-- css
|-- font-awesome.css
|-- template.css
|-- combined.min.css (font-awesome.css + template.css = combined.min.css)
Run Code Online (Sandbox Code Playgroud)
网页包
mix
.sass('resources/sass/font-awesome.scss', 'public/css/font-awesome.css')
.sass('resources/sass/template.scss', 'public/css/template.css');
// combining css files
mix.combine([
'public/css/font-awesome.css',
'public/css/template.css'
], 'public/css/combined.min.css');
Run Code Online (Sandbox Code Playgroud)
当font-awesome.css&template.css文件合并为 时combined.min.css,不再需要它们,javascript文件也是如此。
如何删除这些无用的文件,这可能吗..?
components我正在尝试为我的 Vue.js 项目中的和sub-directories使用创建别名jsconfig.json。但我收到此错误:
jsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@components/*": [
"./src/components/*"
],
}
},
"exclude": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud)
SomeFile.vue
import GuestLayout from '@components/Layouts/GuestLayout';
Run Code Online (Sandbox Code Playgroud)
错误:
ERROR Failed to compile with 1 error
...
To install it, you can run: npm install --save @components/Layouts/GuestLayout
Run Code Online (Sandbox Code Playgroud)
我尝试着解决这个问题,但似乎没有任何效果。这是找到的最简单的一个https://www.youtube.com/watch?v=U73TDohXmhQ
我在这里做错了什么..?
在我的 laravel(7.x) 应用程序中,我有一个通用功能来显示所有模块中所有活动和非活动记录的数量。因此,我有义务在每个模块上重复相同的功能。
例如:Device, DeviceType, DeviceCompany, etc模型有一个相同的方法被调用,_getTotal并且到处都是_getTotal方法在都在做同样的工作。
设备.php
class Device extends Model
{
protected $table = 'devices';
...
public function _getTotal($status = \Common::STATUS_ACTIVE)
{
return self::where([
'status' => $status
])->count() ?? 0;
}
}
Run Code Online (Sandbox Code Playgroud)
设备类型.php
class DeviceType extends Model
{
protected $table = 'device_types';
...
public function _getTotal($status = \Common::STATUS_ACTIVE)
{
return self::where([
'status' => $status
])->count() ?? 0;
}
}
Run Code Online (Sandbox Code Playgroud)
我试图将这种方法放入,Base Model但我认为这可能不是一个好的做法。我对吗..?
有没有办法让这个方法_getTotal成为所有模块的通用方法..?
我是 WordPress 的新手,我创建了一个自定义帖子类型,但即使添加了“页面属性”,我也看不到用于选择自定义模板的模板下拉菜单,只有“订单”字段可见。
我的主题有 3 个不同的菜单(顶部、主菜单和页脚),其中所有这些菜单的每个菜单都有相同的模板,例如:主菜单具有中央、东部、西部、北部和南部的位置,具有相同的布局,顶部相同菜单也是如此。
主菜单和顶部菜单中的每个位置都是一个存档页面,我可以在其中显示该位置帖子的列表以供进一步查看。但是按照传统的存档-{post_type}.php,我必须为每个位置创建一个新的存档页面。
这是主菜单的代码:
[
"capability_type" => "post",
"description" => "Holds our location's specific data",
"public" => true,
"menu_position" => 5,
"has_archive" => true,
"show_admin_column" => true,
"supports" => [
"title",
"editor",
"thumbnail",
"excerpt",
"revisions",
"page-attributes"
],
"taxonomies" => [
"post_tag"
],
"labels" => [
"name" => "Locations",
"singular_name" => "Location",
"add_new" => "Add Location",
"add_new_item" => "Add Location" ,
"edit_item" => "Edit Location",
"new_item" => "New Location",
"all_items" => "Locations" ,
"view_item" => "View Location", …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,有一种情况我必须运行相同的查询 3 次,但每个查询都有一些不同的条件。例如:active:查询+ active conditions、inactive:查询+ inactive conditions。ETC。
这是我的代码:
$activeInventory = $inactiveInventory = \DB::table('device_inventories')
->where([
'device_companies.company_id' => session()->get('COMPANY_ID'),
'device_inventories.device_id' => $Self->id,
])->select([
...
])
->join('devices', 'devices.id', '=', 'device_inventories.device_id')
->join('device_companies', 'device_companies.id', '=', 'devices.device_company_id');
// active records
$active = $activeInventory
->where('device_inventories.status', 'T')
->join('u_devices', 'u_devices.device_inventory_id', '!=', 'device_inventories.id')
->get() ?? null;
// inactive records
$inactive = $inactiveInventory
->where('device_inventories.status', 'F')
->get() ?? null;
// returning data
return [
'model' => $Self,
'active' => $active,
'inactive' => $inactive,
];
Run Code Online (Sandbox Code Playgroud)
请注意,我已u_devices …
laravel ×5
php ×2
alias ×1
api ×1
command ×1
controller ×1
css ×1
execute ×1
file ×1
guard ×1
importerror ×1
javascript ×1
jestjs ×1
laravel-mix ×1
launch ×1
methods ×1
module ×1
node.js ×1
pane ×1
parameters ×1
radix ×1
repeat ×1
resources ×1
select ×1
sql ×1
syntax-error ×1
templates ×1
vue.js ×1
wordpress ×1