message:"Workspace context is required to {$operation}{$model}. No workspace is currently set.",
operation:$operation,
model:$model
);
}
/**
*Createexceptionforcreatingamodel.
*/
publicstaticfunctionforCreate(string$model):self
{
returnnewself(
message:"Cannot create {$model} without workspace context. Ensure a workspace is set before creating workspace-scoped resources.",
operation:'create',
model:$model
);
}
/**
*Createexceptionforqueryscope.
*/
publicstaticfunctionforScope(string$model):self
{
returnnewself(
message:"Cannot apply workspace scope to {$model} without workspace context. Use ->withoutGlobalScope(WorkspaceScope::class) if intentionally querying across workspaces.",
operation:'scope',
model:$model
);
}
/**
*Createexceptionformiddleware.
*/
publicstaticfunctionforMiddleware():self
{
returnnewself(
message:'This route requires workspace context. Ensure you are accessing through a valid workspace subdomain or have a workspace session.',
operation:'middleware'
);
}
/**
*Gettheoperationthatfailed.
*/
publicfunctiongetOperation():?string
{
return$this->operation;
}
/**
*Getthemodelclassthatwasinvolved.
*/
publicfunctiongetModel():?string
{
return$this->model;
}
/**
*RendertheexceptionasanHTTPresponse.
*/
publicfunctionrender(Request$request):Response
{
if($request->expectsJson()){
returnresponse()->json([
'message'=>$this->getMessage(),
'error'=>'missing_workspace_context',
'operation'=>$this->operation,
'model'=>$this->model,
],$this->getCode());
}
// For web requests, show a user-friendly error page