0
votes

I have a question what is the diffrence between \Illuminate\Http\Request and the Request classes in laravel 5. I've use the \Illuminate\Http\Request class for some ajax based thing in blade form.When using \Illuminate\Http\Request shows an error,

Non-static method Illuminate\Http\Request::ajax() should not be called statically, assuming $this from incompatible context

This is the codeblock what I've used

  Route::post('org_tree',function(\Illuminate\Http\Request $request)
    {
         if(Request::ajax())
            {

            }
   });

What is the reason for that?

2
The Request class is simply a Laravel Facade that wraps an instance of \Illuminate\Http\Request. Facades are nothing more than syntactic sugar to grant you static access to the underlying class methods.maiorano84

2 Answers

1
votes

the method ajax is not a static method and this class have no _callStatic magic method so you can use

$request = new \Illuminate\Http\Request();
$request->ajax();

or use

\Illuminate\Http\Request::ajax();
0
votes

After modifying the code using as below the problem resolved

Route::post('org_tree',function(\Illuminate\Http\Request $request)
{
     if($request->ajax())
        {
          //rest of the ajax body 
        }
});

or

Route::post('org_tree',function(Request $request)
{
     if($request->ajax())
        {
          //rest of the ajax body
        }
});

thats it!