Skip to main content

Alerts

Resource alerts appear near the top of the resource detail page.

Use them for model state that should be visible before the user edits or acts on a record: blocked users, archived products, expired contracts or failed synchronizations.

Alert Class

Alerts extend ResourceAlert and render a node.

namespace App\Alerts\Product;

use App\Models\Product;
use Illuminate\Database\Eloquent\Model;
use Qore\Next\System\Node\Alert\AlertType;
use Qore\Next\System\Node\Node;
use Qore\Next\System\Nodes\AlertNode;
use Qore\Next\System\Resource\ResourceAlert;

class ProductIsArchivedAlert extends ResourceAlert
{
public function __construct()
{
$this->setIsShownOnDetail(fn (Product $product): bool => filled($product->archived_at));
}

/**
* @param Product $model
*/
public function render(Model $model): Node
{
return new AlertNode(__('common.products.archived'), AlertType::WARNING);
}
}

Register alerts on the resource:

use App\Alerts\Product\ProductIsArchivedAlert;
use Qore\Next\System\Resource\ResourceAlert;

/**
* @return list<ResourceAlert>
*/
public function alerts(): array
{
return [
new ProductIsArchivedAlert,
];
}

Visibility

ResourceAlert uses the same visibility traits as fields and actions:

  • setIsShownOnCreate(Closure(): bool $callback): static
  • setIsShownOnEdit(Closure(Model): bool $callback): static
  • setIsShownOnDetail(Closure(Model): bool $callback): static
  • setIsShownOnIndex(Closure(): bool $callback): static

Most alerts only need setIsShownOnDetail(), because the default resource pages render alerts on detail pages.

When To Use Alerts

Use alerts to explain current model state.

Use actions when the user needs to do something. Use field visibility when the state only affects one field. Use validation messages when the user submitted invalid data.