Completed
Push — master ( 952c0b...3a671f )
by Sebastian
02:01
created

Html::multiselect()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 1
nop 3
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Html;
4
5
use Illuminate\Contracts\Support\Htmlable;
6
use Illuminate\Http\Request;
7
use Illuminate\Support\Collection;
8
use Illuminate\Support\HtmlString;
9
use Illuminate\Support\Traits\Macroable;
10
use Spatie\Html\Elements\A;
11
use Spatie\Html\Elements\Button;
12
use Spatie\Html\Elements\Div;
13
use Spatie\Html\Elements\Element;
14
use Spatie\Html\Elements\Fieldset;
15
use Spatie\Html\Elements\Form;
16
use Spatie\Html\Elements\Input;
17
use Spatie\Html\Elements\Label;
18
use Spatie\Html\Elements\Legend;
19
use Spatie\Html\Elements\Option;
20
use Spatie\Html\Elements\Select;
21
use Spatie\Html\Elements\Span;
22
use Spatie\Html\Elements\Textarea;
23
24
class Html
25
{
26
    use Macroable;
27
    
28
    /** @var \Illuminate\Http\Request */
29
    protected $request;
30
31
    /** @var \ArrayAccess|array */
32
    protected $model;
33
34
    public function __construct(Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
35
    {
36
        $this->request = $request;
37
    }
38
39
    /**
40
     * @param string|null $href
41
     * @param string|null $text
0 ignored issues
show
Bug introduced by
There is no parameter named $text. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
42
     *
43
     * @return \Spatie\Html\Elements\A
44
     */
45
    public function a($href = null, $contents = null)
46
    {
47
        return A::create()
48
            ->attributeIf($href, 'href', $href)
0 ignored issues
show
Documentation introduced by
$href is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
            ->html($contents);
50
    }
51
52
    /**
53
     * @param string|null $type
54
     * @param string|null $text
0 ignored issues
show
Bug introduced by
There is no parameter named $text. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
55
     *
56
     * @return \Spatie\Html\Elements\Button
57
     */
58
    public function button($contents = null, $type = null)
59
    {
60
        return Button::create()
61
            ->attributeIf($type, 'type', $type)
0 ignored issues
show
Documentation introduced by
$type is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62
            ->html($contents);
63
    }
64
65
    /**
66
     * @param \Illuminate\Support\Collection|iterable|string $classes
67
     *
68
     * @return \Illuminate\Contracts\Support\Htmlable
69
     */
70
    public function class($classes): Htmlable
0 ignored issues
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
71
    {
72
        if ($classes instanceof Collection) {
73
            $classes = $classes->toArray();
74
        }
75
76
        $attributes = new Attributes();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $attributes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
77
        $attributes->addClass($classes);
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $attributes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
78
79
        return new HtmlString(
80
            $attributes->render()
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $attributes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
81
        );
82
    }
83
84
    /**
85
     * @param string|null $name
86
     * @param bool $checked
87
     * @param string|null $value
88
     *
89
     * @return \Spatie\Html\Elements\Input
90
     */
91
    public function checkbox($name = null, $checked = false, $value = '1')
92
    {
93
        return $this->input('checkbox', $name, $value)
94
            ->attributeIf((bool) $this->old($name, $checked), 'checked');
95
    }
96
97
    /**
98
     * @param \Spatie\Html\HtmlElement|string|null $contents
99
     *
100
     * @return \Spatie\Html\Elements\Div
101
     */
102
    public function div($contents = null)
103
    {
104
        return Div::create()->children($contents);
105
    }
106
107
    /**
108
     * @param string|null $name
109
     * @param string|null $value
110
     *
111
     * @return \Spatie\Html\Elements\Input
112
     */
113
    public function email($name = '', $value = '')
114
    {
115
        return $this->input('email', $name, $value);
116
    }
117
118
    /**
119
     * @param string $tag
120
     *
121
     * @return \Spatie\Html\Elements\Element
122
     */
123
    public function element($tag)
124
    {
125
        return Element::withTag($tag);
126
    }
127
128
    /**
129
     * @param string|null $type
130
     * @param string|null $name
131
     * @param string|null $value
132
     *
133
     * @return \Spatie\Html\Elements\Input
134
     */
135
    public function input($type = null, $name = null, $value = null)
136
    {
137
        return Input::create()
138
            ->attributeIf($type, 'type', $type)
0 ignored issues
show
Documentation introduced by
$type is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
139
            ->attributeIf($name, 'name', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
140
            ->attributeIf($name, 'id', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
141
            ->attributeIf($name && $this->old($name, $value), 'value', $this->old($name, $value));
0 ignored issues
show
Bug introduced by
It seems like $this->old($name, $value) targeting Spatie\Html\Html::old() can also be of type array; however, Spatie\Html\BaseElement::attributeIf() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug Best Practice introduced by
The expression $name of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
142
    }
143
144
    /**
145
     * @param \Spatie\Html\HtmlElement|string|null $legend
146
     *
147
     * @return \Spatie\Html\Elements\Fieldset
148
     */
149
    public function fieldset($legend = null)
150
    {
151
        return $legend ?
152
            Fieldset::create()->legend($legend) :
153
            Fieldset::create();
154
    }
155
156
    /**
157
     * @param string $method
158
     * @param string|null $action
159
     *
160
     * @return \Spatie\Html\Elements\Form
161
     */
162
    public function form($method = 'POST', $action = null)
163
    {
164
        $method = strtoupper($method);
165
        $form = Form::create();
166
167
        // If Laravel needs to spoof the form's method, we'll append a hidden
168
        // field containing the actual method
169
        if (in_array($method, ['DELETE', 'PATCH', 'PUT'])) {
170
            $form = $form->addChild($this->hidden('_method')->value($method));
171
        }
172
173
        // On any other method that get, the form needs a CSRF token
174
        if ($method !== 'GET') {
175
            $form = $form->addChild($this->token());
176
        }
177
178
        return $form
179
            ->method($method === 'GET' ? 'GET' : 'POST')
180
            ->attributeIf($action, 'action', $action);
0 ignored issues
show
Documentation introduced by
$action is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
181
    }
182
183
    /**
184
     * @param string|null $name
185
     * @param string|null $value
186
     *
187
     * @return \Spatie\Html\Elements\Input
188
     */
189
    public function hidden($name = null, $value = null)
190
    {
191
        return $this->input('hidden', $name, $value);
192
    }
193
194
    /**
195
     * @param \Spatie\Html\HtmlElement|iterable|string|null $contents
196
     * @param string|null $for
197
     *
198
     * @return \Spatie\Html\Elements\Label
199
     */
200
    public function label($contents = null, $for = null)
201
    {
202
        return Label::create()
203
            ->attributeIf($for, 'for', $this->fieldName($for))
0 ignored issues
show
Documentation introduced by
$for is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
204
            ->children($contents);
205
    }
206
207
    /**
208
     * @param \Spatie\Html\HtmlElement|string|null $contents
209
     *
210
     * @return \Spatie\Html\Elements\Legend
211
     */
212
    public function legend($contents = null)
213
    {
214
        return Legend::create()->html($contents);
0 ignored issues
show
Bug introduced by
It seems like $contents defined by parameter $contents on line 212 can also be of type object<Spatie\Html\HtmlElement>; however, Spatie\Html\BaseElement::html() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
215
    }
216
217
    /**
218
     * @param string $email
219
     * @param string|null $text
220
     *
221
     * @return \Spatie\Html\Elements\A
222
     */
223
    public function mailto($email, $text = null)
224
    {
225
        return $this->a('mailto:'.$email, $text);
226
    }
227
228
    /**
229
     * @param string|null $name
230
     * @param iterable $options
231
     * @param string|iterable|null $value
232
     *
233
     * @return \Spatie\Html\Elements\Select
234
     */
235 View Code Duplication
    public function multiselect($name = null, $options = [], $value = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
236
    {
237
        return Select::create()
238
            ->attributeIf($name, 'name', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
239
            ->attributeIf($name, 'id', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
240
            ->options($options)
0 ignored issues
show
Bug introduced by
It seems like $options defined by parameter $options on line 235 can also be of type array; however, Spatie\Html\Elements\Select::options() does only seem to accept object<Spatie\Html\Elements\iterable>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
241
            ->value($name ? $this->old($name, $value) : $value)
242
            ->multiple();
243
    }
244
245
    /**
246
     * @param string|null $text
247
     * @param string|null $value
248
     * @param bool $selected
249
     *
250
     * @return \Spatie\Html\Elements\Option
251
     */
252
    public function option($text = null, $value = null, $selected = false)
253
    {
254
        return Option::create()
255
            ->text($text)
256
            ->value($value)
257
            ->selectedIf($selected);
258
    }
259
260
    /**
261
     * @param string|null $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
262
     *
263
     * @return \Spatie\Html\Elements\Input
264
     */
265
    public function password($name = null)
266
    {
267
        return $this->input('password', $name);
268
    }
269
270
    /**
271
     * @param string|null $name
272
     * @param bool $checked
273
     * @param string|null $value
274
     *
275
     * @return \Spatie\Html\Elements\Input
276
     */
277
    public function radio($name = null, $checked = false, $value = null)
278
    {
279
        return $this->input('radio', $name, $value)
280
            ->attributeIf((bool) $this->old($name, $checked), 'checked');
281
    }
282
283
    /**
284
     * @param string|null $name
285
     * @param iterable $options
286
     * @param string|iterable|null $value
287
     *
288
     * @return \Spatie\Html\Elements\Select
289
     */
290 View Code Duplication
    public function select($name = null, $options = [], $value = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
291
    {
292
        return Select::create()
293
            ->attributeIf($name, 'name', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
294
            ->attributeIf($name, 'id', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
295
            ->options($options)
0 ignored issues
show
Bug introduced by
It seems like $options defined by parameter $options on line 290 can also be of type array; however, Spatie\Html\Elements\Select::options() does only seem to accept object<Spatie\Html\Elements\iterable>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
296
            ->value($name ? $this->old($name, $value) : $value);
297
    }
298
299
    /**
300
     * @param \Spatie\Html\HtmlElement|string|null $contents
301
     *
302
     * @return \Spatie\Html\Elements\Span
303
     */
304
    public function span($contents = null)
305
    {
306
        return Span::create()->children($contents);
307
    }
308
309
    /**
310
     * @param string|null $test
0 ignored issues
show
Bug introduced by
There is no parameter named $test. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
311
     *
312
     * @return \Spatie\Html\Elements\Button
313
     */
314
    public function submit($text = null)
315
    {
316
        return $this->button($text, 'submit');
317
    }
318
319
    /**
320
     * @param string $number
321
     * @param string|null $text
322
     *
323
     * @return \Spatie\Html\Elements\A
324
     */
325
    public function tel($number, $text = null)
326
    {
327
        return $this->a('tel:'.$number, $text);
328
    }
329
330
    /**
331
     * @param string|null $name
332
     * @param string|null $value
333
     *
334
     * @return \Spatie\Html\Elements\Input
335
     */
336
    public function text($name = null, $value = null)
337
    {
338
        return $this->input('text', $name, $value);
339
    }
340
341
    /**
342
     * @param string|null $name
343
     * @param string|null $value
344
     *
345
     * @return \Spatie\Html\Elements\Textarea
346
     */
347
    public function textarea($name = null, $value = null)
348
    {
349
        return Textarea::create()
350
            ->attributeIf($name, 'name', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
351
            ->attributeIf($name, 'id', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
352
            ->value($this->old($name, $value));
0 ignored issues
show
Bug introduced by
It seems like $this->old($name, $value) targeting Spatie\Html\Html::old() can also be of type array; however, Spatie\Html\Elements\Textarea::value() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
353
    }
354
355
    /**
356
     * @return \Spatie\Html\Elements\Input
357
     */
358
    public function token()
359
    {
360
        return $this->hidden('_token')->value($this->request->session()->token());
0 ignored issues
show
Bug introduced by
The method token() does not seem to exist on object<Symfony\Component...ssion\SessionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
361
    }
362
363
    /**
364
     * @param \ArrayAccess|array $model
365
     *
366
     * @return $this
367
     */
368
    public function model($model)
369
    {
370
        $this->model = $model;
371
372
        return $this;
373
    }
374
375
    /**
376
     * @param \ArrayAccess|array $model
377
     * @param string|null $method
378
     * @param string|null $action
379
     *
380
     * @return \Spatie\Html\Elements\Form
381
     */
382
    public function modelForm($model, $method = 'POST', $action = null): Form
383
    {
384
        $this->model($model);
385
386
        return $this->form($method, $action);
387
    }
388
389
    /**
390
     * @return $this
391
     */
392
    public function endModel()
393
    {
394
        $this->model = null;
395
396
        return $this;
397
    }
398
399
    /**
400
     * @return \Illuminate\Contracts\Support\Htmlable
401
     */
402
    public function closeModelForm(): Htmlable
403
    {
404
        $this->endModel();
405
406
        return $this->form()->close();
407
    }
408
409
    /**
410
     * @param string $name
411
     * @param mixed $value
412
     *
413
     * @return mixed
414
     */
415
    protected function old($name, $value = null)
416
    {
417
        if (empty($name)) {
418
            return;
419
        }
420
421
        // If there's no default value provided, and the html builder currently
422
        // has a model assigned, try to retrieve a value from the model.
423
        if (empty($value) && $this->model) {
424
            $value = $this->model[$name] ?? '';
425
        }
426
427
        return $this->request->old($name, $value);
428
    }
429
430
    /**
431
     * @param string $name
432
     * 
433
     * @return string
434
     */
435
    protected function fieldName($name)
436
    {
437
        return $name;
438
    }
439
440
    protected function ensureModelIsAvailable()
441
    {
442
        if (empty($this->model)) {
443
            throw new Exception('Method requires a model to be set on the html builder');
444
        }
445
    }
446
}
447