0

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
    }
}

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah you beat me by the minute:)
2

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.