Skip to content

Commit

Permalink
Merge pull request #579 from chiragpipariya/patch-2
Browse files Browse the repository at this point in the history
i18nFile & normalFile added two function
  • Loading branch information
nWidart authored Aug 29, 2018
2 parents 31bec71 + b473471 commit 62eeb8c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Modules/Core/macros.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,32 @@
return new HtmlString($string);
});

Form::macro('i18nFile', function ($name, $title, ViewErrorBag $errors, $lang, $object = null, array $options = []) {
if (array_key_exists('multiple', $options)) {
$nameForm = "{$lang}[$name][]";
} else {
$nameForm = "{$lang}[$name]";
}

$options = array_merge(['class' => 'form-control'], $options);

$string = "<div class='form-group " . ($errors->has($lang . '.' . $name) ? ' has-error' : '') . "'>";
$string .= "<label for='$nameForm'>$title</label>";

if (is_object($object)) {
$currentData = $object->hasTranslation($lang) ? $object->translate($lang)->{$name} : '';
} else {
$currentData = false;
}

$string .= Form::file("{$lang}[{$name}]",$options);

$string .= $errors->first("{$lang}.{$name}", '<span class="help-block">:message</span>');
$string .= '</div>';

return new HtmlString($string);
});

/*
|--------------------------------------------------------------------------
| Standard fields
Expand Down Expand Up @@ -346,6 +372,25 @@
return new HtmlString($string);
});

Form::macro('normalFile', function ($name, $title, ViewErrorBag $errors, $object = null, array $options = []) {
$options = array_merge(['class' => 'form-control', 'placeholder' => $title,'multiple'=>'multiple'], $options);

$string = "<div class='form-group " . ($errors->has($name) ? ' has-error' : '') . "'>";
$string .= Form::label($name, $title);

if (is_object($object)) {
$currentData = $object->{$name} ?: '';
} else {
$currentData = null;
}

$string .= Form::file($name,$options);
$string .= $errors->first($name, '<span class="help-block">:message</span>');
$string .= '</div>';

return new HtmlString($string);
});

Response::macro('csv', function ($file, $filename, $status = 200, $headers = []) {
return response($file, $status, array_merge([
'Content-Type' => 'application/csv',
Expand Down

0 comments on commit 62eeb8c

Please sign in to comment.