public function index() {
$query = 'UPDATE `'.DB_PREFIX.'product` AS `p`
INNER JOIN (
SELECT `t`.`sku`, MIN(`p`.`product_id`) AS `product_id`
FROM (
SELECT `sku`, MIN(`price`) AS `price`
FROM `'.DB_PREFIX.'product`
WHERE `quantity` != 0
GROUP BY `sku`
) AS `t`
JOIN `'.DB_PREFIX.'product` AS `p`
ON `p`.`sku` = `t`.`sku` AND `p`.`price` = `t`.`price`
WHERE `p`.`quantity` != 0
GROUP BY `t`.`sku`
) AS `i` ON `i`.`product_id` = `p`.`product_id`
SET `p`.`status` = (`i`.`product_id` IS NOT NULL)';
$response = $this->db->query($query)->rows;
if(is_object($response)){
echo 'Все ок '.$query.' вернул обьект '.PHP_EOL;
}else{
echo 'Все пропало! '.$query.' не вернул обьект! '.PHP_EOL;
}
echo "ok";
}
} else {
return true;
}
update table set field1 = field2 where id in (1,2,3,4,5,6,7,1000);
class Test implements CastsAttributes
{
/**
* Cast the given value.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @return mixed
*/
public function get($model, string $key, $value, array $attributes)
{
dump('U called get');
return $value;
}
/**
* Prepare the given value for storage.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @return mixed
*/
public function set($model, string $key, $value, array $attributes)
{
dump('U called set');
return mb_strtolower($value);
}
}
class User extends Authenticatable
{
.......
protected $casts = [
'email_verified_at' => 'datetime',
'name' => Test::class,
];
......
}
$user = User::first();
dump($user->name, $user->name, $user->name, $user->name, $user->name);
^ "U called get"
^ "U called get"
^ "U called get"
^ "U called get"
^ "U called get"
^ "vasya pupkin"
^ "vasya pupkin"
^ "vasya pupkin"
^ "vasya pupkin"
^ "vasya pupkin"