Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在vuejs中获取记录时出现未知列错误_Javascript_Php_Laravel_Vue.js_Components - Fatal编程技术网

Javascript 在vuejs中获取记录时出现未知列错误

Javascript 在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

我在vue.js和Laravel中找到了一个新记录,我正在根据关系获取记录。但是,当我单击获取记录按钮时,在网络控制台中,我得到了错误SQLSTATE[42S22]:未找到列:1054未知列“products.selected_product_id”(SQL:select*from
products
where
products
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);
                    });
                 },