10
Laravel-Ajaxリクエストかどうかを確認する
私はLaravelでajax呼び出しを判別する方法を見つけようとしましたが、それに関するドキュメントは見つかりません。 私が持っているindex()私は、要求の性質に基づいて異なった状況を処理する関数を。基本的に、これはGETリクエストにバインドされたリソースコントローラメソッドです。 public function index() { if(!$this->isLogin()) return Redirect::to('login'); if(isAjax()) // This is what i am needing. { return $JSON; } $data = array(); $data['records'] = $this->table->fetchAll(); $this->setLayout(compact('data')); } PHPでAjaxリクエストを決定する他の方法は知っていますが、Laravelに固有の何かが必要です。 ありがとう 更新しました: 使ってみた if(Request::ajax()) { echo 'Ajax'; } しかし、私はエラーを受け取っています: Non-static method Illuminate\Http\Request::ajax() should not be called statically, assuming $this from …