scafera/frontend
Scafera Frontend provides a Laravel-ready frontend layer with reusable Blade components, layouts, and asset helpers, helping developers build responsive, maintainable interfaces faster while keeping presentation logic organized and easy to customize.
config/app.php.use Vendor\Package\Facades\TemplateValidator;
$result = TemplateValidator::validate(resource_path('views/welcome.blade.php'));
if ($result->fails()) {
// Inspect rule IDs and messages
dump($result->errors());
}
Where to look first:
First use case: guard template rendering or deployment by validating that a template exists inside the configured templates directory and passes the package’s rules. This is especially useful for user-supplied or generated templates that may point outside the expected directory.
v1.0.2 adds stable rule IDs to validators. Prefer asserting against IDs rather than human-readable messages so your tests and error handling survive wording changes.
$result = TemplateValidator::validate($path);
$this->assertTrue($result->fails());
$this->assertContains('template.location', $result->ruleIds());
Use the same IDs to map validation failures to API error codes, logs, or localized messages:
$messages = [
'template.location' => 'The template must be inside the configured templates directory.',
'template.syntax' => 'The template contains invalid syntax.',
];
The new template location validation rejects files outside the templates directory. Use it as an explicit guard before compiling or rendering templates, particularly when the path comes from user input or a database record.
$validator = TemplateValidator::forPath($templatePath);
if ($validator->fails()) {
abort(422, 'Invalid template location.');
}
return view($templatePath);
Do not hardcode resource_path('views') or a package-specific path in your validation calls. Resolve the templates directory through the same architecture configuration the package now uses. This keeps CLI commands, queued jobs, and HTTP requests consistent.
$templatesPath = config('architecture.templates_path');
If your application supports multiple template roots, normalize and validate each root against the architecture configuration before passing paths to the validator.
Add a validation step to CI or a deployment script so templates outside the allowed directory fail fast:
// tests/Feature/TemplateValidationTest.php
public function test_all_application_templates_are_valid(): void
{
$templates = File::allFiles(config('architecture.templates_path'));
foreach ($templates as $template) {
$result = TemplateValidator::validate($template->getPathname());
$this->assertTrue(
$result->passes(),
"Template [{$template->getPathname()}] failed validation: " . $result->errors()->toJson()
);
}
}
Wrap the validator in a Laravel custom rule when validating uploaded or submitted template references:
class ValidTemplatePath implements ValidationRule
{
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$result = TemplateValidator::validate($value);
if ($result->fails()) {
$fail($result->firstError());
}
}
}
Register custom validators or override messages using the package’s extension points, and keep rule IDs stable in your own mappings.
php artisan config:clear
php artisan config:cache
How can I help you explore Laravel packages today?