Question

For my understanding I try to clarify couple of thing related to laravel

I initiate my controller with the following url

/parser/import/8

which points to

class ParserController extends \BaseController {

 public function __construct() {
        $this->partial = 'admin._partials.parser';
    }

 public function import($id) {
        return \View::make('admin.products.index')
                ->with('product_partial', $this->partial)
                ->with(Parser::importFeed($id))
                ->with('errors');
    }

}

and in my import method I try to initiate a model method passing as argument an ID Parser::importFeed($id)

than in my model I want to create a public variable which should hold the passed via url but initiates all Eloquent.

class Parser extends \Eloquent {

    protected   $table = 'products';

    public      $feed_id;

   public function scopeImportFeed($feed_id) {

        $this->feed_id = $feed_id;
}

If use public static function than I have again problems what is the proper way to initiate model from controller

Était-ce utile?

La solution

The with method requires two arguments, one for the name of the variable and ne for the value but you gave only one, it should be like this:

->with('parser', Parser::importFeed($id))

So you can use $parser in your view. Also in any scope method it accepts the $query at first argument and yo should return the $query as well to allow method chaining, so it should be like this:

public function scopeImportFeed($query, $feed_id) {
    $this->feed_id = $feed_id;
    return $query;
}

So you may use:

Parser::importFeed($id)->get()

But, according to your code, nothing should get returned because you are not doing any query at all.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top