meraproject/vendor/illuminate/support/Traits/Conditionable.php
keboss-m 5c21d25d45 Initial commit: Merakomis portal, Docker stack and user-reader API.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 11:04:05 +03:00

45 lines
1.0 KiB
PHP

<?php
namespace Illuminate\Support\Traits;
trait Conditionable
{
/**
* Apply the callback if the given "value" is truthy.
*
* @param mixed $value
* @param callable $callback
* @param callable|null $default
* @return $this|mixed
*/
public function when($value, $callback, $default = null)
{
if ($value) {
return $callback($this, $value) ?: $this;
} elseif ($default) {
return $default($this, $value) ?: $this;
}
return $this;
}
/**
* Apply the callback if the given "value" is falsy.
*
* @param mixed $value
* @param callable $callback
* @param callable|null $default
* @return $this|mixed
*/
public function unless($value, $callback, $default = null)
{
if (! $value) {
return $callback($this, $value) ?: $this;
} elseif ($default) {
return $default($this, $value) ?: $this;
}
return $this;
}
}