0

我有一个表单,它必须在我的表单中运行存储功能VerificationController.php并在用户表中编辑数据并在验证表中创建记录,并且必须将两个图像保存到特定文件夹中,但是在我发送 ajax 请求之后,什么也没有发生。我还尝试dd()了一些变量的函数,但也没有任何反应。

我的store功能:

public function store(Request $request) 
{
    $request->validate([
      'firstname' => 'required|min:2|max:255',
      'lastname' => 'required|min:2|max:255',
      'id_front' => 'required|image|mimes:jpg,jpeg,png|max:2048',
      'id_back' => 'required|image|mimes:jpg,jpeg,png|max:2048',
    ]);
    
    
    
    if($request->hasFile('id_front') && $request->hasFile('id_back')) {
       $path_front = $request->file('id_front')->store('user_verifications/front/'.$request->user()->id);
       $path_back = $request->file('id_back')->store('user_verifications/back/'.$request->user()->id);
       
       
       $user = auth()->user();
       $user = DB::table('users')->where('id', $user->id)->first();
       $user->verified = "yes";
       $user->save();
       
          
       $verification = new Verification();
       $verification->user_id = $user->id;
       $verification->firstname = $request->input('firstname');
       $verification->lastname = $request->input('lastname');
       $verification->country = $request->input('country');
       $verification->id_front_path = $path_front;
       $verification->id_back_path = $path_back;
       $verification->save();
          
       DB:commit();

    }

Verify.vue还有我的(视图)文件的JS 部分:

data() {
        return {
            verificationForm: this.$inertia.form({
                firstname: '',
                lastname: '',
                country: 'USA',
                options: [
                  { text: 'United States', value: 'USA' },
                  { text: 'United Kingdom', value: 'UK' },
                  { text: 'Afghanistan', value: 'Afghanistan' },
                  { text: 'Albania', value: 'Albania' },
                  { text: 'Algeria', value: 'Algeria' },
                  { text: 'American Samoa', value: 'AmericanSamoa' },
                  { text: 'Andorra', value: 'Andorra' },
                  { text: 'Angola', value: 'Angola' },
                  { text: 'Anguilla', value: 'Anguilla' },
                  { text: 'Antigua and Barbuda', value: 'AntiguaAndBarbuda' },
                  { text: 'Argentina', value: 'Argentina' },
                  { text: 'Armenia', value: 'Armenia' },
                  { text: 'Australia', value: 'Australia' },
                  { text: 'Austria', value: 'Austria' },
                  { text: 'Azerbaijan', value: 'Azerbaijan' },
                  { text: 'Bahamas', value: 'Bahamas' },
                  { text: 'Bahrain', value: 'Bahrain' },
                  { text: 'Bangladesh', value: 'Bangladesh' },
                  { text: 'Barbados', value: 'Barbados' },
                  { text: 'Belarus', value: 'Belarus' },
                  { text: 'Belgium', value: 'Belgium' },
                  { text: 'Belize', value: 'Belize' },
                  { text: 'Bolivia', value: 'Bolivia' },
                  { text: 'Bosnia and Herzegovina', value: 'Bosnia and Herzegovina' },
                  { text: 'Botswana', value: 'Botswana' },
                  { text: 'Brazil', value: 'Brazil' },
                  { text: 'Bulgaria', value: 'Bulgaria' },
                  { text: 'Cambodia', value: 'Cambodia' },
                  { text: 'Cameroon', value: 'Cameroon' },
                  { text: 'Canada', value: 'Canada' },
                  { text: 'Chad', value: 'Chad' },
                  { text: 'Chile', value: 'Chile' },
                  { text: 'China', value: 'China' },
                  { text: 'Colombia', value: 'Colombia' },
                  { text: 'Congo', value: 'Congo' },
                  { text: 'Costa Rica', value: 'Costa Rica' },
                  { text: 'Croatia', value: 'Croatia' },
                  { text: 'Cuba', value: 'Cuba' },
                  { text: 'Cyprus', value: 'Cyprus' },
                  { text: 'Czechia', value: 'Czechia' },
                  { text: 'Denmark', value: 'Denmark' },
                  { text: 'Dominican Republic', value: 'Dominican Republic' },
                  { text: 'Ecuador', value: 'Ecuador' },
                  { text: 'Egypt', value: 'Egypt' },
                  { text: 'Estonia', value: 'Estonia' },
                  { text: 'Ethiopia', value: 'Ethiopia' },
                  { text: 'Finland', value: 'Finland' },
                  { text: 'France', value: 'France' },
                  { text: 'Germany', value: 'Germany' },
                  { text: 'Ghana', value: 'Ghana' },
                  { text: 'Greece', value: 'Greece' },
                  { text: 'Guatemala', value: 'Guatemala' },
                  { text: 'Guyana', value: 'Guyana' },
                  { text: 'Haiti', value: 'Haiti' },
                  { text: 'Honduras', value: 'Honduras' },
                  { text: 'Hong Kong', value: 'Hong Kong' },
                  { text: 'Hungary', value: 'Hungary' },
                  { text: 'Iceland', value: 'Iceland' },
                  { text: 'India', value: 'India' },
                  { text: 'Indonesia', value: 'Indonesia' },
                  { text: 'Iran', value: 'Iran' },
                  { text: 'Iraq', value: 'Iraq' },
                  { text: 'Ireland', value: 'Ireland' },
                  { text: 'Israel', value: 'Israel' },
                  { text: 'Italy', value: 'Italy' },
                  { text: 'Jamaica', value: 'Jamaica' },
                  { text: 'Japan', value: 'Japan' },
                  { text: 'Jordan', value: 'Jordan' },
                  { text: 'Kazakhstan', value: 'Kazakhstan' },
                  { text: 'Kenya', value: 'Kenya' },
                  { text: 'Kuwait', value: 'Kuwait' },
                  { text: 'Kyrgyzstan', value: 'Kyrgyzstan' },
                  { text: 'Latvia', value: 'Latvia' },
                  { text: 'Lebanon', value: 'Lebanon' },
                  { text: 'Liechtenstein', value: 'Liechtenstein' },
                  { text: 'Luxembourg', value: 'Luxembourg' },
                  { text: 'Malaysia', value: 'Malaysia' },
                  { text: 'Maldives', value: 'Maldives' },
                  { text: 'Malta', value: 'Malta' },
                  { text: 'Mexico', value: 'Mexico' },
                  { text: 'Moldova', value: 'Moldova' },
                  { text: 'Monaco', value: 'Monaco' },
                  { text: 'Mongolia', value: 'Mongolia' },
                  { text: 'Mozambique', value: 'Mozambique' },
                  { text: 'Namibia', value: 'Namibia' },
                  { text: 'Nepal', value: 'Nepal' },
                  { text: 'Netherlands', value: 'Netherlands' },
                  { text: 'New Zealand', value: 'New Zealand' },
                  { text: 'Niger', value: 'Niger' },
                  { text: 'Nigeria', value: 'Nigeria' },
                  { text: 'Norway', value: 'Norway' },
                  { text: 'Oman', value: 'Oman' },
                  { text: 'Pakistan', value: 'Pakistan' },
                  { text: 'Panama', value: 'Panama' },
                  { text: 'Paraguay', value: 'Paraguay' },
                  { text: 'Peru', value: 'Peru' },
                  { text: 'Philippines', value: 'Philippines' },
                  { text: 'Poland', value: 'Poland' },
                  { text: 'Portugal', value: 'Portugal' },
                  { text: 'Puerto Rico', value: 'Puerto Rico' },
                  { text: 'Qatar', value: 'Qatar' },
                  { text: 'Romania', value: 'Romania' },
                  { text: 'Russian Federation', value: 'Russian Federation' },
                  { text: 'Saudi Arabia', value: 'Saudi Arabia' },
                  { text: 'Serbia', value: 'Serbia' },
                  { text: 'Seychelles', value: 'Seychelles' },
                  { text: 'Singapore', value: 'Singapore' },
                  { text: 'Slovakia', value: 'Slovakia' },
                  { text: 'Slovenia', value: 'Slovenia' },
                  { text: 'Somalia', value: 'Somalia' },
                  { text: 'South Africa', value: 'South Africa' },
                  { text: 'Spain', value: 'Spain' },
                  { text: 'Sri Lanka', value: 'Sri Lanka' },
                  { text: 'Sudan', value: 'Sudan' },
                  { text: 'Sweden', value: 'Sweden' },
                  { text: 'Switzerland', value: 'Switzerland' },
                  { text: 'Tanzania', value: 'Tanzania' },
                  { text: 'Thailand', value: 'Thailand' },
                  { text: 'Tunisia', value: 'Tunisia' },
                  { text: 'Turkey', value: 'Turkey' },
                  { text: 'Ukraine', value: 'Ukraine' },
                  { text: 'United Arab Emirates', value: 'United Arab Emirates' },
                  { text: 'Uruguay', value: 'Uruguay' },
                  { text: 'Venezuela', value: 'Venezuela' },
                  { text: 'Vietnam', value: 'Vietnam' },
                  { text: 'Yemen', value: 'Yemen' },
                  { text: 'Zambia', value: 'Zambia' },
                  { text: 'Zimbabwe', value: 'Zimbabwe' },
                ],
                id_front: this.id_front,
                id_back: this.id_back,
            }, {
                bag: 'createVerification',
                resetOnSuccess: false,
            }),
        }
    },
    methods: {
        createVerification() {
            this.verificationForm.post('/user/verify', {
                preserveScroll: true,
            });
        }
    }

编辑:1我终于在 Google Chrome 开发工具中发现了这个错误

4

1 回答 1

0

您所说的“什么都没有发生”是什么意思?

如果您的意思是文件(id_back, id_front)不在请求文件中,也许您忘记enctype="multipart/form-data"了表格?

于 2020-11-20T07:53:54.477 回答