Javascript 在vuejs中获取记录时出现未知列错误
我在vue.js和Laravel中找到了一个新记录,我正在根据关系获取记录。但是,当我单击获取记录按钮时,在网络控制台中,我得到了错误SQLSTATE[42S22]:未找到列:1054未知列“products.selected_product_id”(SQL:select*fromJavascript 在vuejs中获取记录时出现未知列错误,javascript,php,laravel,vue.js,components,Javascript,Php,Laravel,Vue.js,Components,我在vue.js和Laravel中找到了一个新记录,我正在根据关系获取记录。但是,当我单击获取记录按钮时,在网络控制台中,我得到了错误SQLSTATE[42S22]:未找到列:1054未知列“products.selected_product_id”(SQL:select*fromproductswhereproductsselected_idin(0)) 请帮我解决这个问题。提前谢谢 SelectedProduct.php <?php namespace Ap
products
whereproducts
selected_idin(0))
请帮我解决这个问题。提前谢谢
SelectedProduct.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class SelectedProduct extends Model
{
public $timestamps = false;
protected $fillable = ['category_id','product_id','priority'];
public function product()
{
return $this->hasOne('App\Product');
}
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use PhpParser\Builder;
class Product extends Model
{
public $incrementing = false;
public $timestamps = false;
protected $fillable = ['id', 'name','hname','code', 'category_id', 'unit_id', 'default_weight', 'weights', 'image', 'status'];
protected static function boot()
{
parent::boot(); // TODO: Change the autogenerated stub
/*static::addGlobalScope('status', function (Builder $builder){
$builder->where('status', true);
});*/
}
protected $casts = [
'status' => 'boolean'
];
public function unit(){
return $this->belongsTo(Unit::class);
}
我认为您需要更新
SelectedProduct
中的product()
关系以使用$this->belongsTo('App\product')代码>
public function getAddedProducts()
{
if (request()->expectsJson()){
$collection = SelectedProduct::with('product')->get();
return response()->json([
'items'=>$collection
]);
}
return view('dashboard');
}
SelectProduct.vue
fetchItems(){
axios.get('/admin/selectedproducts/getAddedProducts')
.then(({ data }) => {
this.items = data.items;
console.log(data);
});
},