doulin2025 2016-05-26 03:39
浏览 386
已采纳

区分Laravel控制器中的GET和POST方法

I have 2 routes like below,

Route::get('/','MainController@Date');
Route::post('/','MainController@Date');

or

Route::any('/','MainController@Date');

When get request is called i will calculate dates and hen post request is called i will get dates from form inputs.

when post method is called in my controler

$date1 = $request->get ( 'date1' );
$date2 = $request->get ( 'date2' );

when get is called

$date1 = will calculate using date function
$date2 = will calculate using date function

How differentiate both methods get and post, if get i should one set of things and for post another set of things

  • 写回答

3条回答 默认 最新

  • duanni5726 2016-05-26 03:47
    关注
        <?php
    
    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    use Illuminate\Routing\Controller;
    
    class SmeController extends Controller
    {
        /**
         * Do somthing
         * @param  Request  $request
         */
        public function update(Request $request)
        {
            if ($request->isMethod('post')) {
        //
            }
            if ($request->isMethod('get')) {
        //
            }
        }
    }
    

    you could also use $method = $request->method();

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部