请问在 api.php 或者 controller 中经常出现 Method not found 是什么问题
比如在教程中写的api中的
<?php
use Illuminate\Http\Request;
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', [
'namespace' => 'App\Http\Controllers\Api'
], function($api) {
// 短信验证码
$api->post('verificationCodes', 'VerificationCodesController@store')
->name('api.verificationCodes.store');
});
$api->post 会出现下划线,说是方法未找到?这是为什么?
又或者在在controller中
public function store(VerificationCodeRequest $request, EasySms $easySms)
{
$phone = $request->phone;
// 生成4位随机数,左侧补0
$code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT);
try {
$result = $easySms->send($phone, [
'content' => "【Lbbs社区】您的验证码是{$code}。如非本人操作,请忽略本短信"
]);
} catch (\Overtrue\EasySms\Exceptions\NoGatewayAvailableException $exception) {
$message = $exception->getException('yunpian')->getMessage();
return $this->response->errorInternal($message ?: '短信发送异常');
}
$key = 'verificationCode_'.str_random(15);
$expiredAt = now()->addMinutes(10);
// 缓存验证码 10分钟过期。
\Cache::put($key, ['phone' => $phone, 'code' => $code], $expiredAt);
return $this->response->array([
'key' => $key,
'expired_at' => $expiredAt->toDateTimeString(),
])->setStatusCode(201);
}
比如
$this->response->errorInternal($message ?: '短信发送异常');
$this->response->array([]);
都会报错Method not found,
虽然并不会影响运行,但是也会感觉蛮不舒服的
请问是什么原因导致的?应该如何去修复
推荐文章: