InvalidStarActorException
The InvalidStarActorException is thrown when attempting to create a star rating without a valid starrer or device identifier.
Namespace
JobMetric\Star\Exceptions\InvalidStarActorException
When It's Thrown
The exception is thrown during star creation when:
- No starrer (user) is provided (
starred_by_typeandstarred_by_idare both null/empty) - No device identifier is provided (
device_idis null/empty) - Both conditions are true (no way to identify the source of the rating)
Exception Details
Message
The exception message is retrieved from the translation file:
trans('star::base.exceptions.invalid_star_actor')
HTTP Status Code
Default HTTP status code: 400 (Bad Request)
How to Avoid
Provide a Starrer
$product->addStar(5, $user); // ✅ Valid - user provided
Provide a Device ID
$product->addStar(5, null, ['device_id' => 'device-123']); // ✅ Valid - device_id provided
Invalid Usage
// ❌ This will throw InvalidStarActorException
$product->addStar(5); // No starrer, no device_id
$product->addStar(5, null); // No starrer, no device_id
$product->addStar(5, null, []); // No starrer, no device_id
Handling the Exception
use JobMetric\Star\Exceptions\InvalidStarActorException;
try {
$product->addStar(5);
} catch (InvalidStarActorException $e) {
return response()->json([
'error' => 'A starrer or device identifier is required',
], 400);
}