Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

laravelio/laravel.io

2497 stars
4 code files
View laravelio/laravel.io on GitHub

resources/macros/blade.php

Open in GitHub
use Illuminate\Support\Facades\Blade;
 
Blade::directive('md', function ($expression) {
return "<?php echo md_to_html($expression); ?>";
});
 
Blade::directive('error', function ($expression) {
return "<?php echo \$errors->first($expression, '<span class=\"help-block\">:message</span>'); ?>";
});
 
Blade::directive('formGroup', function ($expression) {
return "<div class=\"form-group<?php echo \$errors->has($expression) ? ' has-error' : '' ?>\">";
});
 
Blade::directive('endFormGroup', function ($expression) {
return '</div>';
});
 
Blade::directive('title', function ($expression) {
return "<?php \$title = $expression ?>";
});
 
Blade::directive('shareImage', function ($expression) {
return "<?php \$shareImage = $expression ?>";
});

app/Providers/AppServiceProvider.php

Open in GitHub
use Illuminate\Support\ServiceProvider;
 
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
$this->bootMacros();
//
}
 
public function bootMacros()
{
require base_path('resources/macros/blade.php');
}
//
}

resources/views/articles/show.blade.php

Open in GitHub
@title($article->title())
//

resources/views/articles/_form.blade.php

Open in GitHub
//
@formGroup('title')
<label for="title">Title</label>
<input
type="text"
name="title"
id="title"
value="{{ old('title', isset($article) ? $article->title() : null) }}"
class="form-control"
required maxlength="100"
/>
<span class="text-gray-600 text-sm mt-1">Maximum 100 characters.</span>
@error('title')
@endFormGroup
 
@formGroup('body')
<label for="body">Body</label>
 
@include('_partials._editor', [
'content' => isset($article) ? $article->body() : null
])
 
@error('body')
@endFormGroup
//

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.