SQLSTATE [42S22]:“where 子句”中的未知列
Posted
技术标签:
【中文标题】SQLSTATE [42S22]:“where 子句”中的未知列【英文标题】:SQLSTATE[42S22]: Unknown Column in 'where clause' 【发布时间】:2020-02-06 14:59:30 【问题描述】:Error Image
在多供应商网站上工作。当商店/供应商用户想要登录没有问题的普通用户时突然出现此错误 这里有两种类型的用户,一种是供应商或 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;
错误
【问题讨论】:
SQLSTATE[42S22]: Column not found: 1054 Unknown column - Laravel的可能重复 【参考方案1】:将“user_shops”添加到可填充模型 考试:
受保护的 $fillable = ['user_shops'];
或检查模型中是否存在“user_shops”?
【讨论】:
我是这个项目的新手。实现一些问题,模型显示一些 id,location_id,user_id,brand_id,希望在模型中丢失,但 phpmyadmin 将显示该列以上是关于SQLSTATE [42S22]:“where 子句”中的未知列的主要内容,如果未能解决你的问题,请参考以下文章
SQLSTATE [42S22]:找不到列:1054 未知列 - Laravel
SQLSTATE [42S22]:找不到列:1054 未知列 laravel 5.1
SQLSTATE [42S22]:找不到列:在 laravel livewire 项目中
SQLSTATE [42S22]:找不到列:1054 'where 子句'中的未知列'user_id'