Kaviranga
Kaviranga

Reputation: 666

What is the difference between of these two classes in laravel 5?

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?

Upvotes: 0

Views: 196

Answers (2)

Kaviranga
Kaviranga

Reputation: 666

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!

Upvotes: 0

TIANJIAWEI
TIANJIAWEI

Reputation: 11

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();

Upvotes: 1

Related Questions