php 当我点击Laravel时,Form Submit什么也不做[关闭]

vlju58qv  于 2023-09-29  发布在  PHP
关注(0)|答案(1)|浏览(91)

已关闭此问题为not reproducible or was caused by typos。它目前不接受回答。

此问题是由打印错误或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这一个是解决的方式不太可能帮助未来的读者。
4天前关闭。
Improve this question
我创建了一个表单来保存音频文件及其对应的控制器(SoundController)和路由。问题是所有的路线显示在控制器中的意见完美的作品,但我不能似乎或什么都没有发生,当我点击提交按钮.它的行为就像页面被刷新了一样

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Sound;
use Illuminate\Http\Request;

class SoundController extends Controller
{
    public function AllSound(){
        $sounds = Sound::latest()->get();
        return view('admin.all_sound',compact('sounds'));
    } // end function

    public function AddSound(){
        return view('admin.add_sound');
    } // end function

    public function StoreSound(Request $request){

        // validation
        $request->validate([
            'name' => 'required|max:200',
            'so_file' => 'required',
            'caty' => 'required'
        ]);

        
            $file = $request->file("so_file");
            $filename = date('YmdHi').$file->getClientOriginalName();
            $move = $file->move(public_path('upload/sound_files/'),$filename);
            

           if($move){
            $sound = new Sound();
            $sound->name = $request->input('so_name');
            $sound->type = $request->input('caty');
            $sound->music = $filename;

            $sound->save();
            $notification = array(
                'message' => 'Sound saved Successfully',
                'alert-type' => 'success'
            );
            return redirect()->route('all.sound')->with($notification);
           }else{
            $notification = array(
                'message' => 'Sound not moved !',
                'alert-type' => 'error'
            );
            return redirect()->route('all.sound')->with($notification);
           }

        
    } // end function
}

这些是我的路线。是storeSound将其保存在数据库中。

Route::get('/admin/all/sounds', [SoundController::class, 'AllSound'])->name('all.sound');
    Route::get('/admin/add/sounds', [SoundController::class, 'AddSound'])->name('add.sound');
    Route::get('/edit/sound/{id}',[SoundController::class, 'EditSound'])->name('edit.sound');
    Route::get('/delete/sound/{id}',[SoundController::class, 'DeleteSound'])->name('delete.sound');
    Route::post('/store/sound',[SoundController::class, 'StoreSound'])->name('store.sound');

我试着在控制台或任何地方检查每一个错误,但没有显示页面就像刷新,但奇怪的是,我所有的其他职位在其他控制器工作完美,这是我的形式添加一个音频。我的PHP版本是8.1.13和Laravel版本10

<form class="forms-sample" action="{{ route('store.sound') }}" method="POST" enctype="multipart/form-data" >
                            @csrf

                            <div class="mb-3">
                                <label for="so_name" class="form-label">Name</label>
                                <input type="text" name="so_name" class="form-control 
                                @error('so_name') is-invalid @enderror">
                            
                           @error('so_name')
                            <span class="text-danger"> {{ $message }} </span>
                           @enderror
                           
                           
                            </div>
                            <div class="mb-3">
                                <label for="caty" class="form-label">Type</label>
                                <select name="caty">
                                    <option value="asmr">ASMR</option>
                                    <option value="whiteNoise">White Noise</option>
                                    <option value="sleep">Sleep</option>
                                    <option value="nature">Nature</option>
                                    <option value="instru">Instrumentals</option>
                                </select>
                            
                           @error('caty')
                            <span class="text-danger"> {{ $message }} </span>
                           @enderror
                           
                           
                            </div>
                            <div class="mb-3">
                                <label for="so_file" class="form-label">Sound File</label>
                                <input type="file" name="so_file" class="form-control 
                                @error('so_file') is-invalid @enderror">
                            
                           @error('so_file')
                            <span class="text-danger"> {{ $message }} </span>
                           @enderror
                           
                           
                            </div>
                            <button type="submit" class="btn btn-primary me-2">Save changes</button>
                            
                        </form>
9nvpjoqh

9nvpjoqh1#

这是由于验证错误..添加此代码在上面的你的形式,然后看看你面临的错误

@if($errors->has())
    @foreach ($errors->all() as $error)
        <div>{{ $error }}</div>
    @endforeach
@endif

相关问题