-
resources/macros/blade.php
Open in GitHubuse 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 GitHubuse 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 //