سؤال

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
    }
}
هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top