jeudi 9 avril 2020

Laravel ONLY on Live Server Error MethodNotAllowedHttpException

I'm getting this error overnight, despite I haven't updated any file. The website has been working perfectly fine for 3 weeks and I am suddenly getting this error when trying to submit anything through POST method. I'm hosting two laravel-based websites and it's happening in both of them. Any idea would be really appreciated. Thanks in advance

Laravel error Img

routes/web.php

Route::post('/post-create', 'PostController@create')->name('post_create');

Post creation form

                    <form method="POST" action="" enctype="multipart/form-data">
                        @csrf
                        <div class="form-group row">
                            <label for="level" class="col-md-4 col-form-label text-md-right">Level</label>
                            <div class="col-md-6">
                                <select id="level" class="form-control" name="level" autocomplete="email">
                                    <option value="red">red</option> 
                                    <option value="yellow">yellow</option> 
                                    <option value="blue">blue</option>
                                    <option value="orange">orange</option> 
                                    <option value="purple">purple</option> 
                                    <option value="silver">silver</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="name" class="col-md-4 col-form-label text-md-right">Title</label>
                            <div class="col-md-6">
                                <input id="name" type="text" class="form-control" name="title" required autofocus>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="message" class="col-md-4 col-form-label text-md-right">Message</label>
                            <div class="col-md-6">
                                <input id="message" type="text" class="form-control" name="message">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="upload_file" class="col-md-4 col-form-label text-md-right">Upload File</label>
                            <div class="col-md-6">
                                <input class="form-control" type="file" name="upload_file" id="upload_file">
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="offset-md-4 col-md-6">
                                <input id="post_submit" type="submit" class="form-control btn btn-primary">
                            </div>
                        </div>
                    </form>

Create method

    public function create(Request $data)
{   
    /* Save file */
    $file = $data->file('upload_file');
    $fileName = $file->getClientOriginalName();
    $filePath = '/pdf/' . $data->level . '/';
        /* Define proper path for local/live version */
        if(strpos(public_path(),"xampp")){
            $filePrePath = public_path(); 
        }else{
            $filePrePath = "/home/drezbkku/englishplus.drezacademy.com";
        }
    $file->move($filePrePath . $filePath, $fileName);

    /* Create Post */
    $post = Post::create([
        'title' => $data->title,
        'message' => $data->message,
        'filelink' => $filePath . $fileName,
        'level'=> $data->level
    ]);

    /* Return redirect */
    return redirect()->route('home');
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire