Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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运行功能_Php_Laravel_Post_Laravel Routing - Fatal编程技术网

Php 刀片中按钮的Laravel运行功能

Php 刀片中按钮的Laravel运行功能,php,laravel,post,laravel-routing,Php,Laravel,Post,Laravel Routing,我在获取刀片文件中的按钮以正确运行控制器中的功能时遇到问题,当我单击该按钮时,我得到一个methodnotallowedexception,并且无法找出哪些设置不正确 据我所知,这就像另一个按钮,我有一个不同的刀片和控制器,除非我忽略了什么,这就是为什么我在这里。如果您需要其他代码,请告诉我 首先,我的路线: Route::post('/viewPatient/{user}/discharge', 'PatientController@discharge')->name('patients

我在获取刀片文件中的按钮以正确运行控制器中的功能时遇到问题,当我单击该按钮时,我得到一个methodnotallowedexception,并且无法找出哪些设置不正确

据我所知,这就像另一个按钮,我有一个不同的刀片和控制器,除非我忽略了什么,这就是为什么我在这里。如果您需要其他代码,请告诉我

首先,我的路线:

Route::post('/viewPatient/{user}/discharge', 'PatientController@discharge')->name('patients.discharge');
Route::post('/viewPatient/{user}/reAdmitt', 'PatientController@reAdmitt')->name('patients.reAdmitt');  
Route::post('/viewPatient/{user}/reAdmitted', 'PatientController@reAdmitted')->name('patients.reAdmitted');
接下来,控制器开始工作

public function discharge(User $user)
    {
        $user->discharged = true;
        $user->discharged_date = now();
        $user->current_facility_id = null;
        $user->save();
        // find all the users documents that are not historical
        $documents = Document::where('user_id', $user->id)->where('historical', false)->get();
        // mark them all as historical
        foreach($documents as $document){
            $document->historical = true;
            $document->save();
        }

        return $this->index(); 
    }

    public function reAdmitt(User $user)
    {
        $user->discharged = false;
        $user->readmitting = true;
        $user->reAdmission_start = now();
        $user->save();

        return $this->index(); 
    }

    public function reAdmitted(User $user)
    {
        $user->discharged = false;
        $user->readmitting = false;
        $user->reAdmitted_on = now();
        $user->save();

        return $this->index(); 
    }
最后是按钮本身

<button><a href="{{route('patients.reAdmitt', $user)}}">Readmitt Patient</a></button>
<button><a href="{{route('patients.reAdmitted', $user)}}">Patient Signed reAdmission</a></button>
<button><a href="{{route('patients.discharge', $user)}}">Discharge Patient</a></button>


预期的结果是,它应该运行函数并更新数据库。我知道出院的函数是有效的,因为我不小心将路径更改为get,当页面加载并将其中一名患者标记为出院时,它就运行了。

您没有提交任何表单。所以你不需要使用邮政路线<代码>标记用于获取路由。因此,改变你的路线作为

Route::get('/viewPatient/{user}/discharge', 'PatientController@discharge')->name('patients.discharge');
Route::get('/viewPatient/{user}/reAdmitt', 'PatientController@reAdmitt')->name('patients.reAdmitt');  
Route::get('/viewPatient/{user}/reAdmitted', 'PatientController@reAdmitted')->name('patients.reAdmitted')

)

简单的按钮将触发一个
GET
请求,但是您将路由定义为一个
POST
请求-
route::POST(…
)。一般的经验法则是,如果该操作将是破坏性的(即CrUD),那么它应该是一个POST请求。因此,我将您的按钮更改为一个带有隐藏字段的实际表单。