根据我的理解,我试图澄清与laravel相关的几件事
我使用以下网址启动我的控制器
/parser/import/8
指向
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');
}
}
在我的导入方法中,我尝试启动一个模型方法作为参数传递一个ID Parser::importFeed($id)
比我的模型中我想要创建一个公共变量,它应该保存传递的via url但是启动所有Eloquent。
class Parser extends \Eloquent {
protected $table = 'products';
public $feed_id;
public function scopeImportFeed($feed_id) {
$this->feed_id = $feed_id;
}
如果使用公共静态函数比我再次出现问题,从控制器
启动模型的正确方法是什么答案 0 :(得分:0)
with
方法需要两个参数,一个用于变量的名称,ne用于值,但是你只给了一个,它应该是这样的:
->with('parser', Parser::importFeed($id))
因此,您可以在$parser
中使用view
。同样在任何scope
方法中,它在第一个参数处接受$query
,并且yo应该返回$query
以允许方法链接,因此它应该是这样的:
public function scopeImportFeed($query, $feed_id) {
$this->feed_id = $feed_id;
return $query;
}
所以你可以使用:
Parser::importFeed($id)->get()
但是,根据你的代码,因为你根本没有进行任何查询,所以不应该返回任何内容。