doulin2025 2016-05-26 11: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 11: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条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?