dougang8233 2014-11-21 12:45
浏览 323

Laravel - 如何检查数据是否存在?

How to check if data exist, if it not exist then redirect to different page.

It keep saying data is exist even it does not exist.

In the model file, I have:

public static function getPackage($id)
{
    return Packages::where('id', '=', $id);
}

In the controller:

protected function checkPackage($id) 
{
    if (!Packages::getPackage($id)->get()) {
        Redirect::to('/')
    } 
}
  • 写回答

3条回答 默认 最新

  • drzip28288 2014-11-21 12:50
    关注

    Model

    public static function getPackage($id)
    {
    $something = Packages::where('id', '=', $id)->get();
    return $something;
    }
    

    in controller

    protected function checkPackage($id) 
    {
    $variable = getPackage();
    if (!$variable ) 
    {
        Redirect::to('/')
    } 
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试