SQLSTATE [42S22]:“ where子句”中的未知列

时间:2019-10-09 09:43:01

标签: mysql sql laravel

Error Image enter image description here

在多供应商网站上工作。当商店/供应商用户想要正常登录时突然出现此错误 在此情况下,两种类型的用户之一是供应商或ShopOwner /另一位普通客户,当供应商要登录时出现此错误。但是普通用户没有登录面临的问题。添加了新列,但问题是继续出现SQL完整性错误。

Query:  (SQL: select * from `shops` where `user_shops` = 233 limit 1)

这里是登录控制器。

  

登录控制器的详细信息

public function userlogin(Request $request){
        $data = Cart::getContent();
        $this->validate($request, [
            'email' => 'required',
            'password' => 'required',
            ],[
            'email.required' => 'Email not matched with Database!',
            'password.required' => 'Password not matched with Database!',
            ]);

        $checkUserInput = filter_var($request->input('email'), FILTER_VALIDATE_EMAIL)?'email': 'username';
        $user = Auth::guard('web')->attempt([$checkUserInput => $request->email,'password'=>$request->password]);
        if($user == 'true'){
            if(Auth::user()->is_activated == 1){
                if(count($data)>0){
                  if(count(Cart::session(Auth::user()->id)->getContent())>0){
                     foreach ($data as $key => $value) {
                       if(!Cart::session(Auth::user()->id)->get($value->id) ){
                          Cart::session(Auth::user()->id)->add($value->id, $value->name,$value->price,$value->quantity, $value->image,array('color' => $value->attributes->color));
                       }else{
                         Cart::session(Auth::user()->id)->update($value->id, array(
                           'quantity' => array(
                               'relative' => false,
                               'value' => $request->quantity
                           ),
                           'attributes' => array(
                             'color' => $value->attributes->color
                           ),
                         ));
                       }
                     }
                  }else{
                    foreach ($data as $key => $value) {
                      Cart::session(Auth::user()->id)->add($value->id, $value->name,$value->price,$value->quantity, $value->image,array('color' => $value->attributes->color));
                    }
                  }
                }


                if(Auth::user()->user_type == 2){
                  $model = Shop::where('user_id',Auth::user()->$user_id)->first();   

                  if($model){
                    if($request->previous){
                      return redirect()->route('neneMart.dashboard');
                    }else{
                      return Redirect::to($request->previous);
                    }
                  }else{
                    if(empty($request->previous)){
                      return redirect()->route('create-shop');
                    }else{

                      return Redirect::to($request->previous);
                    }
                  }
                }else{
                  if(empty($request->previous)){
                    return redirect()->route('home');
                  }else{
                    return Redirect::to($request->previous);
                  }
                }
             }
            else{
                return redirect()->route('user-login')->with(Auth::logout())->with('error', 'User email has not been activated yet!');
            }
        }else{
            return redirect()->route('user-login')->with('error', 'Whoops! Wrong Email or Username or Password !');
        }
    }`
  

路线

Route:: get('user-login', 'Auth\LoginController@usershowLoginForm')->name('user-login');
Route:: post('userLogin', 'Auth\LoginController@userlogin')->name('userLogin');
  

商店管理控制器

public function index()
{
    $shop = Shop::where('user_id',Auth::user()->id)->first();
    $model = ShopManagement::where('shop_id','Nenemart-'.$shop->id)->first();
    $shopid = 'Nenemart-'.$shop->id;
    $agent = new Agent();
    if($agent->isMobile() || $agent->isTablet()){
      return view('mobile.mart.shopmanagemnt',compact('model','shopid'));
    }else{
      return view('frontend.mart.shopmanagemnt',compact('model','shopid'));
    }

}

public function vendorShop(){
  $shop = Shop::where('user_id',Auth::user()->id)->first();
  $model = ShopManagement::where('shop_id','Nenemart-'.$shop->id)->first();
  $vendorProducts = Product::orderBy('id', 'dese')->where('created_by', $shop->id)->where('type', 1)->get();
  $agent = new Agent();
  if($agent->isMobile() || $agent->isTablet()){
    return view('mobile.mart.vendorShop',compact('model', 'vendorProducts'));
  }else{
    return view('frontend.mart.vendorShop',compact('model', 'vendorProducts'));
  }

}

商店管理模型

     protected $table = 'shop_management';
  protected $primaryKey = 'id';

  public static function getImage($shop_id){
    $model = Self::where('shop_id','Nenemart-'.$shop_id)->first();
    if($model){
      return $model->shop_logo;
    }else{
      return '';
    }
  }
}

**商店型号**

  <?php

namespace App\Model\Frontend;

use Illuminate\Database\Eloquent\Model;
use Session;
use App\Model\Product;
use App\Model\MobileColor;
use App\Http\Controllers\HomeController;
use Auth;
use DB;
class Shop extends Model
{
    protected $fillable = [
        'user_id', 'shop_name', 'complex_name', 'brand_category_id',  'shop_mobile', 'shop_phone', 'trade_license', 'address', 'city', 'zipcode', 'opening_day', 'opening_time', 'closing_time'
    ];

    public static function checkShopIsVerified($user_id){
      $model = Self::where('user_id',$user_id)->where('status',1)->first();
      if($model){
        return true;
      }else{
        return false;
      }
    }
    public static function getTodayOrder(){
      $shop = Shop::where('user_id',Auth::user()->id)->first();
      if($shop){
        $data = DB::select("SELECT po.*, pod.id as pod_id,pod.product_id,pod.color_id,pod.quantity,pod.price,pod.status as p_status,p.product_code,p.model,p.type FROM product_order as po RIGHT JOIN product_order_details as pod ON po.id = pod.order_id JOIN products as p on p.id = pod.product_id WHERE p.created_by = ".$shop->id." and p.type = 1 and pod.status = 0 and po.date=".date('Y-m-d')." order by po.id desc");
        $array = Self::processData($data);
      }else{
        $array = array();
      }
      return sizeof($array);
    }

    public static function getTotalCompleteOrder(){
      $shop = Shop::where('user_id',Auth::user()->id)->first();
      if($shop){
        $data = DB::select("SELECT po.*, pod.id as pod_id,pod.product_id,pod.color_id,pod.quantity,pod.price,pod.status as p_status,p.product_code,p.model,p.type FROM product_order as po RIGHT JOIN product_order_details as pod ON po.id = pod.order_id JOIN products as p on p.id = pod.product_id WHERE p.created_by = ".$shop->id." and p.type = 1 and pod.status = 1 order by po.id desc");
        $array = Self::processData($data);
      }else{
        $array = array();
      }
      return sizeof($array);
    }
    public static function getTotalPendingOrder(){

        $data = DB::select("SELECT po.*, pod.id as pod_id,pod.product_id,pod.color_id,pod.quantity,pod.price,pod.status as  p_status,p.product_code,p.model,p.type FROM product_order as po RIGHT JOIN product_order_details as pod ON po.id = pod.order_id JOIN products as p on p.id = pod.product_id WHERE p.type = 1 and pod.status = 0 order by po.id desc");
        $array = Self::processData($data);
      return sizeof($array);
    }
    public static function getmonthlySale(){
      $first_day_this_month = date('Y-m-01'); // hard-coded '01' for first day
      $last_day_this_month  = date('Y-m-t');
      $total = 0;
      $shop = Shop::where('user_id',Auth::user()->id)->first();
      if($shop){
        $data = DB::select("SELECT pod.quantity*pod.price as total FROM product_order as po RIGHT JOIN product_order_details as pod ON po.id = pod.order_id JOIN products as p on p.id = pod.product_id WHERE p.created_by = ".$shop->id." and p.type = 1 and pod.status = 1 and po.date between ".$first_day_this_month." and ".$last_day_this_month." order by po.id desc");
        if(sizeof($data)>0){
          foreach($data as $d){
            $total +=$d->total;
          }
        }
      }
      return $total;
    }

错误

1 个答案:

答案 0 :(得分:0)

将“ user_shops”添加到可填充模型 考试:

受保护的$ fillable = ['user_shops'];

还是检查模型中是否存在“ user_shops”?