1. Go to this page and download the library: Download ayra/laravel-themes library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ayra / laravel-themes example snippets
use Ayra\Theme\Facades\Theme;
// Set theme and layout
Theme::uses('default')->layout('main');
// Render a view
return Theme::view('home.index', ['title' => 'Welcome']);
namespace App\Http\Controllers;
use Ayra\Theme\Facades\Theme;
class HomeController extends Controller
{
public function index()
{
Theme::uses('default')->layout('main');
return Theme::view('home.index', [
'title' => 'Welcome to Our Site',
'description' => 'A beautiful theme-powered website'
]);
}
}
// Switch theme and persist in session/cookie
Theme::switch('dark-theme', true);
// Switch theme for current request only
Theme::switch('light-theme', false);
// Get current theme from session/cookie
$currentTheme = Theme::getCurrentTheme();
// Check if specific theme is active
if (Theme::isActive('dark-theme')) {
// Dark theme specific logic
}
// Clear theme session/cookie
Theme::clearTheme();
// Preview theme: /home?theme=dark-theme
// Preview layout: /home?layout=mobile
// Add middleware to routes
Route::get('/home', function () {
return Theme::view('home.index');
})->middleware('theme.preview');
// Apply theme middleware to routes
Route::get('/admin', function () {
return Theme::view('admin.dashboard');
})->middleware('theme:admin,admin-layout');
// Route groups with theme
Route::group(['middleware' => 'theme:mobile,mobile-layout'], function () {
Route::get('/mobile', function () {
return Theme::view('mobile.home');
});
});
// In your theme config.php or controller
$asset = Theme::asset();
// Add CSS and JS files
$asset->add('bootstrap', 'css/bootstrap.min.css');
$asset->add('jquery', 'js/jquery.min.js', ['bootstrap']);
// Theme-specific assets
$asset->themePath()->add('custom', 'css/custom.css');
// External CDN assets
$asset->add('fontawesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css');
// Set layout
Theme::layout('admin');
// Multiple layouts
Theme::layout('mobile')->uses('mobile-theme');
// Basic view
Theme::view('home.index', $data);
// With specific theme and layout
Theme::uses('admin')->layout('dashboard')->view('admin.dashboard', $data);
// Scope to theme directory
Theme::scope('home.index', $data)->render();
// Watch both theme and app views
Theme::watch('home.index', $data)->render();
namespace App\Widgets;
use Ayra\Theme\Widget;
class WidgetUserProfile extends Widget
{
public function render($data = [])
{
return view('widgets.user-profile', $data);
}
}
// In Blade templates
@widget('user-profile', ['user' => $user])
// In PHP
Theme::widget('user-profile', ['user' => $user])->render();
// Format dates
format_date('2024-01-15', 'F j, Y') // January 15, 2024
human_date('2024-01-15') // 2 months ago
time_ago('2024-01-15') // 2 months ago
// Date checks
is_weekend('2024-01-15') // false
is_business_day('2024-01-15') // true
// Age calculation
get_age('1990-05-20') // 33
// Number formatting
format_bytes(1024) // 1 KB
format_number(1500) // 1.5K
format_currency(99.99, 'USD') // $99.99
// Text formatting
slugify('Hello World!') // hello-world
truncate('Long text here...', 10) // Long text...
word_limit('Many words in this sentence', 5) // Many words in this...
// Search highlighting
highlight_search('Hello World', 'world') // Hello <mark>World</mark>
// Password & token generation
generate_password(16, true) // Random secure password
generate_token(32) // Random hex token
// Data masking
mask_email('[email protected]') // us**@ex***.com
mask_phone('+1-555-123-4567') // +1-5**-***-4567
// Email protection
protectEmail('[email protected]') // JavaScript-protected email link
// Device type
is_mobile() // true/false
is_tablet() // true/false
is_desktop() // true/false
// Browser information
$browser = get_browser_info();
// Returns: ['browser' => 'Chrome', 'version' => '120.0', 'os' => 'Windows']
// Client information
get_client_ip() // Client IP address
get_country_code() // Country code from IP
// Random test data
get_random_name() // John Smith
get_random_email() // [email protected]
get_random_company() // TechCorp
get_random_phone() // +1-555-123-4567
get_random_address() // 123 Main St, New York, NY 10001
get_random_website() // https://www.example.com
// Random quotes
get_random_quote() // Inspirational quote
// Basic meta tags
meta_init() // Common meta tags
// Custom meta tags
meta_tags([
'title' => 'Page Title',
'description' => 'Page description',
'keywords' => 'laravel, themes'
])
// SEO tags
seo_tags(
'Page Title',
'Page description',
'keywords',
'Author Name',
'https://example.com/image.jpg',
'https://example.com/page'
)
// Load assets based on conditions
$asset->addConditional('mobile', 'mobile-css', 'css/mobile.css');
$asset->addConditional('desktop', 'desktop-css', 'css/desktop.css');
// In your Blade templates
@if(request()->isMobile())
@foreach(Theme::asset()->getConditionalAssets('mobile') as $name => $asset)
<link rel="stylesheet" href="{{ $asset['path'] }}">
@endforeach
@endif
// Enable optimization for production
if (app()->environment('production')) {
Theme::asset()->optimize(true);
}
// This will automatically use minified versions if they exist
// css/style.css → css/min/style.min.css
// Switch theme with persistence
Theme::switch('dark-theme', true);
// Switch theme for current request only
Theme::switch('light-theme', false);
// Check current theme
$currentTheme = Theme::getCurrentTheme();
// Check if specific theme is active
if (Theme::isActive('dark-theme')) {
// Dark theme specific logic
}
namespace App\Http\Controllers;
use Ayra\Theme\Facades\Theme;
class HomeController extends Controller
{
public function index()
{
// Switch theme based on user preference
if (request()->has('theme')) {
Theme::switch(request()->get('theme'), true);
}
// Get theme statistics
$stats = Theme::getThemeStats(Theme::getCurrentTheme());
// Prepare data with helper functions
$data = [
'title' => 'Welcome to ' . get_random_company(),
'description' => 'A beautiful site created on ' . human_date(now()),
'stats' => $stats,
'isMobile' => is_mobile(),
'browserInfo' => get_browser_info(),
'randomQuote' => get_random_quote()
];
return Theme::view('home.index', $data);
}
}
{{-- In your Blade templates --}}
<div class="sidebar">
@widget('user-profile', ['user' => auth()->user()])
@widget('recent-posts', ['limit' => 5])
</div>
// In your theme config.php
'asset' => function($asset) {
// Enable CDN for production
if (app()->environment('production')) {
$asset->enableCdn('https://cdn.example.com');
}
// Add core assets
$asset->add('bootstrap', 'css/bootstrap.min.css');
$asset->add('jquery', 'js/jquery.min.js', ['bootstrap']);
// Add theme assets with versioning
$asset->addVersioned('main', 'css/main.css');
$asset->addVersioned('app', 'js/app.js');
// Add conditional assets based on device
if (is_mobile()) {
$asset->addConditional('mobile', 'mobile-css', 'css/mobile.css');
$asset->addConditional('mobile', 'mobile-js', 'js/mobile.js');
}
// Add assets with integrity
$asset->addWithIntegrity('bootstrap', 'css/bootstrap.min.css', 'sha384-...');
// Disable CDN
$asset->disableCdn();
}
// Create named containers for different sections
$asset->container('header')->add('header-css', 'css/header.css');
$asset->container('footer')->add('footer-js', 'js/footer.js');
// In your Blade templates
@styles('header')
@scripts('footer')
// Company information
$companyInfo = [
'name' => get_random_company(),
'founded' => '1995',
'employees' => format_number(rand(50, 1000)),
'revenue' => format_currency(rand(1000000, 10000000), 'USD')
];
// Team member cards
@foreach($team as $member)
<div class="team-member">
<img src="{{ get_gravatar_url($member->email, 200) }}" alt="{{ $member->name }}">
<h3>{{ $member->name }}</h3>
<p>{{ $member->position }}</p>
<p>Member since {{ human_date($member->joined_at) }}</p>
</div>
@endforeach
// Enable optimization in production
if (app()->environment('production')) {
Theme::asset()->optimize(true);
}
// Use CDN for external assets
$asset->enableCdn('https://cdn.example.com');
$asset->add('bootstrap', 'css/bootstrap.min.css');
$asset->disableCdn();
// Asset versioning for cache busting
$asset->addVersioned('main', 'css/main.css');
// Load heavy assets only when needed
if (request()->routeIs('blog.*')) {
$asset->addConditional('blog', 'blog-css', 'css/blog.css');
$asset->addConditional('blog', 'blog-js', 'js/blog.js');
}
if (request()->routeIs('admin.*')) {
$asset->addConditional('admin', 'admin-css', 'css/admin.css');
$asset->addConditional('admin', 'admin-js', 'js/admin.js');
}
// Protect email addresses from bots
<p>Contact us at: {!! protectEmail('[email protected]') !!}</p>
// Mask sensitive information
<p>Phone: {{ mask_phone('+1-555-123-4567') }}</p>
<p>Email: {{ mask_email('[email protected]') }}</p>
// Add SRI (Subresource Integrity) for external assets
$asset->addWithIntegrity('bootstrap', 'css/bootstrap.min.css', 'sha384-...');
// In your theme's config.php or a custom helper file
if (!function_exists('theme_specific_helper')) {
function theme_specific_helper($value) {
return 'Theme: ' . $value;
}
}
// Use in your views
{{ theme_specific_helper('Hello World') }}
// Create custom theme class
class CustomTheme extends \Ayra\Theme\Theme
{
public function customMethod()
{
return 'Custom functionality';
}
}
// Register in service provider
$this->app->singleton('theme', function($app) {
return new CustomTheme($app['config'], $app['events'], $app['view'], $app['asset'], $app['files'], $app['breadcrumb'], $app['manifest']);
});
bash
# Create different themes for different purposes
php artisan theme:create admin
php artisan theme:create mobile
php artisan theme:create corporate
php artisan theme:create blog
bash
# Create a global widget
php artisan theme:widget UserProfile --global
# Create a theme-specific widget
php artisan theme:widget RecentPosts default
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.