Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 8中的验证_Php_Laravel 8_Laravel Validation - Fatal编程技术网

Php Laravel 8中的验证

Php Laravel 8中的验证,php,laravel-8,laravel-validation,Php,Laravel 8,Laravel Validation,我正在尝试在Laravel 8中创建一个个性化请求 class SendContactFormRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; }

我正在尝试在Laravel 8中创建一个个性化请求

class SendContactFormRequest 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:4|max:30',
            'email' => 'required|email',
            'phone' => 'required|numeric|size:11',
            'message' => 'required|min:4|max:400',
        ];
    }
}
在我的控制器中,我使用它发送电子邮件

public function sendContactForm(SendContactFormRequest $request)
{
    try {
        $data = [
            'name' => $request->get('name'),
            'email' => $request->get('email'),
            'phone' => $request->get('phone'),
            'message' => $request->get('message'),
        ];
        // SEND EMAIL
        $this->sendNotification($data);

        return redirect()
            ->back()
            ->with('success', trans('web.'));

    } catch (Exception $e) {
        return redirect()
            ->back()
            ->with('danger', $e->getMessage());
    }
}
但是总是返回
HTTP错误500
我不知道我做错了什么。。。我正在看任何教程和代码示例,但我不知道这是我的问题

已更新

最后我做到了:

首先,我正在创建一个
个性化请求

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;


class SendContactFormRequest 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|string|max:20',
            'email'   => 'required|email|unique:users,email',
            'phone'   => 'required|numeric|min:10',
            'message' => 'required|string|max:400',
        ];
    }
}
现在我是用户
$request->variable
,在我使用
$request->get()
之前,我配置了通知并发送电子邮件ok

现在我的问题是,我把我的联系表格空了,我不能显示信息。。。但现在我可以看到我的apache日志,我有:

[

我在
wampServer
中将该值增加到512MB,但结果相同。我认为我的代码没有验证我的表单,但我不明白我不知道我做错了

更新

函数发送通知

/**
     * SEND NOTIFICATION WHEN CONTACT FORM IT´S SEND
     */
    public function sendNotification($data)
    {
        $emailTo = "";
        $details = [
            'name'      => $data["name"],
            'email'     => $data["email"],
            'phone'     => $data["phone"],
            'message'   => $data["message"],
        ];

        Notification::route('mail', $emailTo)->notify(new newMessage($details));
        
       
        return redirect()->back()->with('success', 'Notificación enviada');
    }

我通过以下方式解决我的问题:

$data = [
                'name'      => $request->name,
                'email'     => $request->email,
                'phone'     => $request->phone,
                'message'   => $request->message,
            ];

            $validator = Validator::make($data,[
                'name'      => 'required|string|min:3|max:125',
                'email'     => 'required|string|email|max:100',
                'phone'     => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:9',
                'message'   => 'required|string|max:400'
            ]);

            if ($validator->fails()) {
                return back()->withErrors($validator);
            }else{
    
                // SEND EMAIL
                $this->sendNotification($data);
    
                return redirect()
                    ->back()
                    ->with('success', trans('web.contact_form_send'));
            }

500错误是一个通用的错误消息,几乎涵盖了PHP脚本可能出现的每一个错误。请检查服务器错误日志以了解确切的错误消息。对于Laravel,也请检查
storage/logs
@aynber thaks中的日志以了解您的响应,但此im中的日志为空。您应该在此处安装并配置x-debug并观察它在何处中断。如果您没有使用artisan,请检查您的apache或nginx日志。另外,请确保APP_DEBUG为true。没有日志似乎很奇怪。我看到的每个实例都默认为storage/logs/laravel.log。您自定义了日志配置吗?@FranCerezo感谢您的回复。我知道在这一点上,我的应用程序坏了,它在验证中。我到达功能验证,但我不知道我的应用程序坏了
/**
     * SEND NOTIFICATION WHEN CONTACT FORM IT´S SEND
     */
    public function sendNotification($data)
    {
        $emailTo = "";
        $details = [
            'name'      => $data["name"],
            'email'     => $data["email"],
            'phone'     => $data["phone"],
            'message'   => $data["message"],
        ];

        Notification::route('mail', $emailTo)->notify(new newMessage($details));
        
       
        return redirect()->back()->with('success', 'Notificación enviada');
    }
$data = [
                'name'      => $request->name,
                'email'     => $request->email,
                'phone'     => $request->phone,
                'message'   => $request->message,
            ];

            $validator = Validator::make($data,[
                'name'      => 'required|string|min:3|max:125',
                'email'     => 'required|string|email|max:100',
                'phone'     => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:9',
                'message'   => 'required|string|max:400'
            ]);

            if ($validator->fails()) {
                return back()->withErrors($validator);
            }else{
    
                // SEND EMAIL
                $this->sendNotification($data);
    
                return redirect()
                    ->back()
                    ->with('success', trans('web.contact_form_send'));
            }