-2

i got this error

Non-static method Illuminate\Http\Request::get() should not be called statically

and this is my code

tanaman = tanaman::where('nama_tanaman', '=', Request::get('nama_tanaman'))->first();
    if ($tanaman === null) {

any solution ?

  • When you get an error message, always start by googling it. There are _many_ questions/answers about it all over. – M. Eriksson Jun 10 '21 at 05:07

1 Answers1

0

The error message is due to the call not going through the Request facade.

use Illuminate\Http\Request;

class YourController extends Controller {
    public function YourMethodName(Request $request) {
        tanaman = tanaman::where('nama_tanaman', $request->nama_tanaman)->first();
    }
}

Or you can call request facade as below:

class MyController() {
    protected $request;
    public function __construct(\Illuminate\Http\Request $request) {
        $this->request = $request;
    }

    public function myFunc() {
        $input = $this->request->all();
    }
}
Hedayatullah Sarwary
  • 2,664
  • 3
  • 24
  • 38