想象一下你有一个控制器或一些代码,看起来像这样:
<?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 的答案。
这是一个有点笼统的问题,与 c 编程语言并不完全相关,但这是我目前正在研究的问题。
为什么一个整数占用 4 个字节或多少字节取决于系统?
为什么每个整数不占用 1 个字节?
例如为什么以下占用8个字节:
int a = 1;
int b = 1;
Run Code Online (Sandbox Code Playgroud)
谢谢