|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hafijul233\Form\Providers\Components; |
|
4
|
|
|
|
|
5
|
|
|
use Collective\Html\FormFacade as Form; |
|
6
|
|
|
use Collective\Html\HtmlFacade as Html; |
|
7
|
|
|
use Illuminate\Support\Facades\URL; |
|
8
|
|
|
use Illuminate\Support\ServiceProvider; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class LabelServiceProvider |
|
12
|
|
|
*/ |
|
13
|
|
|
class LabelServiceProvider extends ServiceProvider |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Register the service provider. |
|
17
|
|
|
* |
|
18
|
|
|
* @return void |
|
19
|
|
|
*/ |
|
20
|
|
|
public function register() |
|
21
|
|
|
{ |
|
22
|
|
|
// |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Get the services provided by the provider. |
|
27
|
|
|
* |
|
28
|
|
|
* @return array |
|
29
|
|
|
*/ |
|
30
|
|
|
public function provides() |
|
31
|
|
|
{ |
|
32
|
|
|
return []; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Loading All Label Style |
|
37
|
|
|
*/ |
|
38
|
|
|
public function boot() |
|
39
|
|
|
{ |
|
40
|
|
|
//Labels |
|
41
|
|
|
Form::macro('nLabel', function ($name, $value, $required = false, $options = []) { |
|
42
|
|
|
if ($required) { |
|
43
|
|
|
$value .= '<span style="color: #dc3545; font-weight:700">*</span>'; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return Form::label($name, $value, $options, false); |
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
Form::macro('hLabel', function ($name, $value, $required = false, $col_size = 2, $options = []) { |
|
50
|
|
|
if ($required) { |
|
51
|
|
|
$value .= '<span style="color: #dc3545; font-weight:700">*</span>'; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return Form::label($name, $value, array_merge(['class' => "col-md-$col_size col-form-label"], $options), false); |
|
55
|
|
|
}); |
|
56
|
|
|
|
|
57
|
|
|
Form::macro('fLabel', function ($name, $value, $required = false, $options = []) { |
|
58
|
|
|
if ($required) { |
|
59
|
|
|
$value .= '<span style="color: #dc3545; font-weight:700">*</span>'; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return str_replace('label', 'span', Form::label($name, $value, $options, false)); |
|
63
|
|
|
}); |
|
64
|
|
|
|
|
65
|
|
|
//Errors |
|
66
|
|
|
Form::macro('nError', function ($name, $msg = null) { |
|
67
|
|
|
return '<span id="'.$name.'-error" class="invalid-feedback">'.$msg.'</span>'; |
|
68
|
|
|
}); |
|
69
|
|
|
|
|
70
|
|
|
Form::macro('hError', function ($name, $msg = null) { |
|
71
|
|
|
return '<span id="'.$name.'-error" class="invalid-feedback">'.$msg.'</span>'; |
|
72
|
|
|
}); |
|
73
|
|
|
|
|
74
|
|
|
Form::macro('fError', function ($name, $msg = null) { |
|
75
|
|
|
return '<span id="'.$name.'-error" class="invalid-feedback">'.$msg.'</span>'; |
|
76
|
|
|
}); |
|
77
|
|
|
|
|
78
|
|
|
//Actions |
|
79
|
|
|
Form::macro('nSubmit', function ($name, $value, $options = []) { |
|
80
|
|
|
$attributes = array_merge($options, ['class' => 'btn btn-primary fw-bold', 'name' => $name, 'type' => 'submit']); |
|
81
|
|
|
|
|
82
|
|
|
return Form::button('<i class="mdi mdi-check-bold fw-bold"></i> '.$value, $attributes); |
|
83
|
|
|
}); |
|
84
|
|
|
|
|
85
|
|
|
Form::macro('nCancel', function ($title, $options = []) { |
|
86
|
|
|
$attributes = array_merge($options, ['class' => 'btn btn-danger fw-bold']); |
|
87
|
|
|
|
|
88
|
|
|
return Html::link(URL::previous(), '<i class="mdi mdi-close-outline fw-bolder"></i> '.$title, $attributes, null, false); |
|
89
|
|
|
}); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|