我刚开始一个新的网站,我想利用Eloquent.在播种我的数据库的过程中,我注意到如果我在模型中包含了任何类型的构造函数,那么我会添加空行.例如,运行此播种机:
<?php
class TeamTableSeeder extends Seeder {
public function run()
{
DB::table('tm_team')->delete();
Team::create(array(
'city' => 'Minneapolis',
'state' => 'MN',
'country' => 'USA',
'name' => 'Twins'
)
);
Team::create(array(
'city' => 'Detroit',
'state' => 'MI',
'country' => 'USA',
'name' => 'Tigers'
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
以此作为我的团队课程:
<?php
class Team extends Eloquent {
protected $table = 'tm_team';
protected $primaryKey = 'team_id';
public function Team(){
// null
}
}
Run Code Online (Sandbox Code Playgroud)
收益率:
team_id | city | state | country | name | created_at | updated_at …Run Code Online (Sandbox Code Playgroud) 我正在尝试测试我雄辩的模型,但我的测试仍然失败了"Class'Eloquent'not found'错误.如果我添加一个使用我的雄辩模型的路线并简单地打印存储在数据库中的一些信息,一切正常.只有在尝试运行phpunit时,才会发现eloquent没有被发现的问题.我的模型在应用程序/模型中,所以它应该包含在作曲家类图中,我已经完成了composer dump-autoload.我敢肯定我忽略了一些非常明显但我无法理解的东西.知道问题是什么吗?
我的测试:
class GameTest extends TestCase {
public function setUp(){
$this->game = Game::find(1);
}
public function testGameInstance(){
$this->assertInstanceOf('Game', $this->game);
}
}
Run Code Online (Sandbox Code Playgroud)
我的模特:
class Game extends Eloquent{
protected $table = 'gm_game';
protected $primaryKey = 'game_id';
}
Run Code Online (Sandbox Code Playgroud) 单击分页链接时,我无法保留搜索参数.例如,如果搜索查询返回40条记录并且我有两个页面,则单击第二页将返回完整记录集的第二页,而不是仅返回搜索返回的40条记录.
这是postIndex()我的控制器:
public function postIndex(){
$validator = Validator::make(
Input::all(),
array('priceMin' => array('numeric'),
'priceMax' => array('numeric')
)
);
if ($validator->fails()){
return Redirect::to('items')->withInput()->withErrors($validator);
} else {
return Redirect::to('items')->withInput();
}
}
Run Code Online (Sandbox Code Playgroud)
我的getIndex():
public function getIndex(){
$items= $this->retriever->getListings(Input::old(), 20);
return View::make('listings', array('items' => $items);
}
Run Code Online (Sandbox Code Playgroud)
然后,retriever对象循环遍历旧输入并查找所有有效的搜索参数,使用它们查询数据库,以及具有指定量的分页,在本例中为20.
我已经尝试使用,->appends()但随后数据不在,Input::old()如果有10个搜索参数,它会产生一个可怕的URL,因为它使用GET和不使用POST.如何将参数应用于分页链接?