Api Reference - Streats22/LaraGrapePackage GitHub Wiki
Comprehensive documentation for LaraGrape service classes, methods, and integration points.
The BlockService
handles dynamic block loading, management, and GrapesJS integration.
App\Services\BlockService
Returns all available blocks organized by category.
use App\Services\BlockService;
$blockService = new BlockService();
$blocks = $blockService->getBlocks();
// Returns:
[
'components' => [
[
'id' => 'button',
'label' => 'Button',
'content' => '<button class="btn">Click me</button>',
'category' => 'components'
],
// ... more blocks
],
'layouts' => [
// ... layout blocks
],
// ... more categories
]
Returns blocks formatted for GrapesJS block manager.
$grapesJsBlocks = $blockService->getGrapesJsBlocks();
// Returns array of blocks with GrapesJS format:
[
[
'id' => 'button',
'label' => 'Button',
'content' => '<button class="btn">Click me</button>',
'category' => 'components',
'attributes' => [
'draggable' => true,
'droppable' => true,
'removable' => true,
'copyable' => true
]
]
]
Renders a block preview for the GrapesJS editor.
$preview = $blockService->renderBlockPreview('button');
// Returns HTML string of the block
Finds the Blade file path for a block by ID.
$filePath = $blockService->findBlockFileById('button');
// Returns: /path/to/resources/views/filament/blocks/components/button.blade.php
The service automatically scans for blocks in:
resources/views/filament/blocks/
├── components/
├── content/
├── forms/
├── layouts/
└── media/
Blocks are defined with metadata comments:
{{-- @block id="my-block" label="My Block" description="Description" --}}
<div class="my-block">
<h3 data-gjs-type="text" data-gjs-name="title">Title</h3>
</div>
The SiteSettingsService
manages site-wide configuration and settings.
App\Services\SiteSettingsService
Returns all site settings as an array.
use App\Services\SiteSettingsService;
$siteSettings = new SiteSettingsService();
$settings = $siteSettings->getSettings();
// Returns all settings from database
Gets a specific setting by key.
$siteName = $siteSettings->getSetting('site_name', 'Default Site Name');
$logoUrl = $siteSettings->getSetting('logo_url');
Returns header-specific settings.
$headerSettings = $siteSettings->getHeaderSettings();
// Returns:
[
'logo_text' => 'Site Name',
'logo_image' => '/path/to/logo.png',
'background_color' => '#ffffff',
'text_color' => '#000000',
'sticky_header' => true,
'show_search' => false
]
Returns footer-specific settings.
$footerSettings = $siteSettings->getFooterSettings();
// Returns:
[
'footer_text' => '© 2024 Site Name',
'background_color' => '#f8f9fa',
'text_color' => '#6c757d',
'show_social' => true,
'social_links' => [
'facebook' => 'https://facebook.com/site',
'twitter' => 'https://twitter.com/site'
]
]
Returns SEO-related settings.
$seoSettings = $siteSettings->getSeoSettings();
// Returns:
[
'default_title' => 'Site Name',
'default_description' => 'Site description',
'default_keywords' => 'keyword1, keyword2',
'google_analytics' => 'GA_TRACKING_ID'
]
Generates CSS from settings for dynamic styling.
$css = $siteSettings->getAllCss();
// Returns CSS string with dynamic values from settings
- General: Site name, contact info, address
- Header: Logo, colors, navigation settings
- Footer: Footer content, social links
- SEO: Meta tags, analytics
- Social: Social media URLs
- Advanced: Custom CSS, JavaScript
The GrapesJsConverterService
handles conversion between GrapesJS data and HTML.
App\Services\GrapesJsConverterService
Converts GrapesJS JSON data to HTML.
use App\Services\GrapesJsConverterService;
$converter = new GrapesJsConverterService();
$html = $converter->convertToHtml($grapesJsJsonData);
// Returns rendered HTML string
Converts HTML to GrapesJS format (if needed).
$grapesJsData = $converter->convertToGrapesJs($html);
Extracts CSS styles from GrapesJS data.
$styles = $converter->extractStyles($grapesJsData);
// Returns CSS string
App\Models\Page
protected $fillable = [
'title',
'slug',
'content',
'grapesjs_data',
'blade_content',
'meta_title',
'meta_description',
'meta_keywords',
'is_published',
'published_at',
'template'
];
Returns 'slug' for route model binding.
Scope for published pages only.
$publishedPages = Page::published()->get();
App\Models\CustomBlock
protected $fillable = [
'name',
'description',
'category',
'html_content',
'css_content',
'js_content',
'grapesjs_attributes',
'is_active',
'sort_order'
];
App\Models\SiteSettings
protected $fillable = [
'key',
'value',
'type',
'group'
];
App\Models\TailwindConfig
Generates CSS for utility classes.
Generates CSS for site theme.
Generates CSS for admin theme.
App\Http\Controllers\PageController
Displays a page by slug.
public function show($slug)
{
$page = Page::where('slug', $slug)->published()->firstOrFail();
return view('pages.show', compact('page'));
}
App\Http\Controllers\AdminPageController
Serves block previews for GrapesJS.
public function blockPreview($blockId)
{
$blockService = new BlockService();
$preview = $blockService->renderBlockPreview($blockId);
return response($preview)->header('Content-Type', 'text/html');
}
App\Filament\Resources\PageResource
- Tabbed interface (Basic Info, Visual Editor, Content, SEO)
- GrapesJS editor integration
- SEO management
- Publishing controls
App\Filament\Resources\CustomBlockResource
- Visual block builder
- Live preview
- HTML/CSS/JS editors
- GrapesJS integration
App\Filament\Resources\SiteSettingsResource
- Grouped settings interface
- Color pickers
- File uploads
- Dynamic form fields
App\Filament\Resources\TailwindConfigResource
- Color palette management
- Typography settings
- Spacing configuration
- Theme generation
php artisan laragrape:setup [options]
-
--all
: Complete setup -
--migrate
: Run migrations -
--seed
: Run seeders -
--force
: Overwrite files
php artisan tailwind:rebuild
- Generates dynamic CSS from TailwindConfig
- Creates utility classes
- Updates theme files
- Copies to public directory
use App\Services\BlockService;
use App\Services\SiteSettingsService;
class HomeController extends Controller
{
public function index(BlockService $blockService, SiteSettingsService $siteSettings)
{
$blocks = $blockService->getGrapesJsBlocks();
$headerSettings = $siteSettings->getHeaderSettings();
return view('home', compact('blocks', 'headerSettings'));
}
}
@php
$siteSettings = app(\App\Services\SiteSettingsService::class);
$headerSettings = $siteSettings->getHeaderSettings();
@endphp
<header style="background-color: {{ $headerSettings['background_color'] }}">
{{ $headerSettings['logo_text'] }}
</header>
use App\Services\BlockService;
$blockService = new BlockService();
$customBlocks = $blockService->getBlocks();
// Add to GrapesJS
foreach ($customBlocks as $category => $blocks) {
foreach ($blocks as $block) {
// Add to GrapesJS block manager
}
}
All services include comprehensive error handling:
try {
$blocks = $blockService->getBlocks();
} catch (\Exception $e) {
Log::error('Failed to load blocks: ' . $e->getMessage());
$blocks = []; // Fallback to empty array
}
- Installation Guide
- [Block System](Block System.md)
- [Component System](Block System.md)
- [Custom Blocks](Custom Block System.md)
- [Troubleshooting](Common Issues.md)
The API is designed to be intuitive, extensible, and well-documented for easy integration into your Laravel applications! 🔧