小编Ben*_*rne的帖子

模拟 Laravel Eloquent save() 方法

想象一下你有一个控制器或一些代码,看起来像这样:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;

class TeamController {

    public function create(Request $request): JsonResponse
    {
        $request->validated();

        $team = new Team(['name' => $request->get('name')]);
        if (!$team->save()) {
            // some really important logic you want to cover
            // cover by a test.
        }

        ...
    }

}
Run Code Online (Sandbox Code Playgroud)

您无法轻松地模拟 Eloquent 模型而不感到有点混乱,请参阅我关于如何从save()调用返回false 的答案。

testing model laravel eloquent

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

为什么 int 在 c 或任何其他语言中占用 4 个字节?

这是一个有点笼统的问题,与 c 编程语言并不完全相关,但这是我目前正在研究的问题。

为什么一个整数占用 4 个字节或多少字节取决于系统?

为什么每个整数不占用 1 个字节?

例如为什么以下占用8个字节:

int a = 1;
int b = 1;
Run Code Online (Sandbox Code Playgroud)

谢谢

c int

0
推荐指数
1
解决办法
1453
查看次数

标签 统计

c ×1

eloquent ×1

int ×1

laravel ×1

model ×1

testing ×1