samedi 30 juin 2018

store foreign key as zero instead of it's value

I have a table that all the values are foreign keys ,when I store these values it save it as zero not the value that I chose ,

public function create()
{
    $type=type::query()->pluck('type');
    $color=color::query()->pluck('colore');
    $region=region::query()->pluck('country');
    $size=size::query()->pluck('size');
    $brand=brand::query()->pluck('company');
    //$price=new_product::query()->pluck('price');
    return view('sale',compact('type','color','region','size','brand'));
}

public function store(Request $request)
{

    new_product::create($request->all());
    return redirect()->route('sale.index');
}

the model:

class new_product extends Model

{ protected $table = 'enter_new_product'; protected $fillable = ['type_id', 'color_id', 'region_id', 'size_id', 'brand_id','price'];

public function type()
{
    return $this->hasMany(type::class);
}

public function size()
{
    return $this->hasMany(size::class);
}

public function color()
{
    return $this->hasMany(color::class);
}

public function region()
{
    return $this->hasMany(region::class);
}

public function brand()
{
    return $this->hasMany(brand::class);
}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2KDVWkY
via IFTTT

Aucun commentaire:

Enregistrer un commentaire