我有付款模式,并希望在付款确认后触发自定义事件。
我的模型代码:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Payment extends Model
{
protected $dates = [
'created_at', 'updated_at', 'confirmed_at',
];
public function confirmed(){
$this->setAttribute('confirmed_at', now());
$this->setAttribute('status', 'confirmed');
}
}
Run Code Online (Sandbox Code Playgroud) 考虑一组检查工作,每个检查工作都有独立的逻辑,因此它们似乎很适合并发运行,例如:
type Work struct {
// ...
}
// This Check could be quite time-consuming
func (w *Work) Check() bool {
// return succeed or not
//...
}
func CheckAll(works []*Work) {
num := len(works)
results := make(chan bool, num)
for _, w := range works {
go func(w *Work) {
results <- w.Check()
}(w)
}
for i := 0; i < num; i++ {
if r := <-results; !r {
ReportFailed()
break;
}
}
}
func ReportFailed() {
// …
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的 Laravel 7 应用程序编写一些测试。但我一直面临A facade root has not been set.
错误。
<?php
namespace Tests\Feature;
use Illuminate\Support\Facades\Config;
use PHPUnit\Framework\TestCase;
class AddressListenerRepositoryTest extends TestCase
{
public function testCreate()
{
Config::set('x', 'address_listeners'); // Cause of "A facade root has not been set" error
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释这个错误的原因吗?
我想从控制台获取文件路径并检查该文件是否为 vm 文件。我写了这段代码:
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Println("Enter the path of the vm file:")
path, _ := reader.ReadString('\n')
if filepath.Ext(path) != ".vm" {
fmt.Println("Error! file must be vm file")
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用。我刚开始学习 Go 所以如果这是一个基本错误,请接受我的道歉。