我创建了一个自定义请求以进行自己的验证。当我遵循这些article时。
我创建了 ProfileRequest
php artisan make:request ProfileRequest
在我的 ProfileRequest
中<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ProfileRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|min:10',
'age' => 'required|numeric'
];
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProfileController extends Controller
{
public function update(ProfileRequest $request){
return "123";
}
}
它返回如下错误:
Class App\Http\Controllers\ProfileRequest does not exist
先生,我需要您的帮助。有人知道如何使用自定义请求吗?
答案 0 :(得分:2)
在 ProfileRequest 中,更改将FormRequest
扩展到Request
。并在课程上方添加use Illuminate\Http\Request;
。代码如下。
<?php
namespace App\Http\Requests;
use Illuminate\Http\Request;
class ProfileRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|min:10',
'age' => 'required|numeric'
];
}
}
并将此App\Http\Requests\ProfileRequest;
放在上面的控制器中。
答案 1 :(得分:0)
您需要在控制器中导入print("Covert binary to decimal (Example: 1011 = 11)");
binary = input("Enter number in Binary Format: ");
try:
#convert input to integer
binary_con = int(binary)
#convert binary to decimal
decimal = int(binary, 2);
#print decimal
print(binary,"in Decimal =",decimal);
#if error print input number is not a interger(1 or 0)
except ValueError:
#print message input number is not binary
print("That's not a Binary number")
like:App\Http\Requests\ProfileRequest
然后尝试:use App\Http\Requests\ProfileRequest
,composer dumpautoload
答案 2 :(得分:0)
您已导入use Illuminate\Http\Request;
您必须在控制器上导入ProfileRequest
而不是Request
,
就这样:
use App\Http\Requests\ProfileRequest;
答案 3 :(得分:0)
尝试一下, 首先,您必须在控制器中导入请求,
use App\Http\Requests\ProfileRequest;
$validated = $request->validated();
if ($validated) {
// ...
}
希望这会有所帮助:)
答案 4 :(得分:0)
在您的ProfileRequest.php中 更改
$(".twentytwenty-container").twentytwenty({
before_label: 'Before',
after_label: 'After'
});
到
use Illuminate\Foundation\Http\FormRequest;
然后
use Illuminate\Http\FormRequest;
答案 5 :(得分:0)
创建ProfileRequest
php artisan make:request Profile/ProfileRequest
在ProfileRequest内部
<?php
namespace App\Http\Requests\Profile;
use Illuminate\Foundation\Http\FormRequest;
class ProfileUpdate extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|min:10',
'age' => 'required|numeric'
];
}
}
然后在控制器中使用App\Http\Requests\Profile\ProfileRequest
。