使用自定义方法模型laravel删除记录错误
用户模型使用自定义方法模型laravel删除记录错误,laravel,laravel-4,laravel-routing,Laravel,Laravel 4,Laravel Routing,用户模型 public function take($id){ return $this->find($id); } public function kill(){ return $this->delete(); } 路由错误1 Route::get('delete/{userid}', function($id) { $user = new User; $user->take($id); //result the content of $
public function take($id){
return $this->find($id);
}
public function kill(){
return $this->delete();
}
路由错误1
Route::get('delete/{userid}', function($id)
{
$user = new User;
$user->take($id); //result the content of $id
$user->kill();
});
我不能删除这些路由记录,只能显示空白页(没有错误)
路由错误2
Route::get('delete/{userid}', function($id)
{
User::take($id)->kill();
});
通过上面的路由,我得到一个错误:不应该静态调用非静态方法User::take()
但我可以用这条路线删除
Route::get('show/{userid}', function($id)
{
$user = new User;
$user->take($id)->kill();
});
Route::get('show/{$id}', function($id)
{
$user = new User;
$user->find($id)->kill();
});
我认为接受的参数必须具有传递给闭包的相同内容。我想使用我的自定义方法take($id),而不是find(),如果可能的话,不必链接find()和kill()。不要用take()来获取你想要的记录量,用find()来查找id。非常感谢兄弟,我应该这样做。