Change value of an SQL column

0

I am doing a project in laravel and MYSQL, I would like to know if there is any way that if the stock is different to 0 the state becomes 'not available', in case there is no MYSQL, there is a manager of DDBB that allows me?

    
asked by Ricardo Alvarado 05.05.2018 в 21:16
source

1 answer

0

In the Producto model you can create a method that returns the stock of each product, so instead of doing $producto->stock you would $producto->inStock() .

/** Devuelve la cantidad en stock y si no hay disponibles devuelve "No disponible" */
public function inStock()
{
    return $this->stock === 0 ? 'No Disponible' : $this->stock;
}
    
answered by 06.05.2018 / 19:07
source