dongzhong5967 2016-08-17 11:09
浏览 48

Laravel 5 - Request :: Method()返回错误的请求类型,Input :: all()返回空

After I deploy my Laravel web application to my host, my code was not work as local. I have a form and POST it to a route, it calls a controller that handles any type of requests. I want to react for each type of request, but Request::Method() function returns GET.

Route:

Route::any('/', [
'as' => 'root', 'uses' => 'WelcomeController@index']);

Blade:

<form action="{{ URL::route('root') }}" method="POST">
    <input type="hidden" name="_token" value="{{{ csrf_token() }}}">
    <input type="hidden" name="newsId" value="{{ $newsId }}">
    <input type="hidden" name="orders" id="orders" value="">
    <button class="btn" name="next">NEXT</button>
    <button class="btn" name="save">SAVE</button>
</form>

Controller:

if (Request::isMethod('get')) {
    $newsId = (Auth::user()->last_news_id % 100) + 1;
    $sentences = News::find($newsId)->sentences;
    return view('summarizer')->with(['sentences' => $sentences, 'newsId' => $newsId]);
} elseif (Request::isMethod('POST')) {
    return 'post';
}

Also I used Request::Method() and it retures GET for all time! I tested this codes in my localhost and it works perfectly.

EDIT: I'm surprising that Input::all() returns empty value too. It works in local well.

  • 写回答

3条回答 默认 最新

  • dongshuofu0039 2016-08-17 11:33
    关注

    Try this way -- Make the Request class dependency injection in index() method. like this

    public function index(Request $request) {
      if ($request->isMethod('get')) {
       // your code
      }elseif ($request->isMethod('post')) {
       // your code
      }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题