Question

I trying to insert data to database using laravel 4 eloquent model. But throws the error:

"Call to undefined method Illuminate\Support\Facades\Request::save() "

I am new to laravel don't know where I Have gone wrong.

my UsersController.php code

public function postRequest() { 
    $request = new Request;
    $request->vms = Input::get('vms');
    $request->location = Input::get('location');
    $request->descr = Input::get('descr');
    $request->status = Input::get('status');
    $request->save();
}

My Request.php Model

<?php

class Request extends Eloquent {

    protected $table = 'requests';
    protected $fillable = array('vms', 'location', 'descr', 'status');

    public function ruser() {
        return $this->hasOne('Ruser'); // this matches the Eloquent model
    }
}
Was it helpful?

Solution

The problem is that your Request model name conflicts with Laravel Request class. You have two options:

1) Namespace your model:

<?php namespace App;

class Request extends Eloquent {

  ...

}

Then use it as:

$request = new App\Request;

2) Rename your model.

OTHER TIPS

Seems like your hitting the laravel "Request" facade, instead of your Request model.

Could you try to prefix your new class call with the correct namespaces?

$request = new yourname\yourpackage\Request();

Or, best of all, call it something else?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top