Laravel - check if Ajax request

后端 未结 11 840
梦谈多话
梦谈多话 2020-12-08 00:09

I have been trying to find a way to determine ajax call in Laravel but i don\'t find any document regarding it.

I have a index() function which i want t

11条回答
  •  孤街浪徒
    2020-12-08 00:13

    You are using the wrong Request class. If you want to use the Facade like: Request::ajax() you have to import this class:

    use Illuminate\Support\Facades\Request;
    

    And not Illumiante\Http\Request


    Another solution would be injecting an instance of the real request class:

    public function index(Request $request){
        if($request->ajax()){
            return "AJAX";
        }
    

    (Now here you have to import Illuminate\Http\Request)

提交回复
热议问题