Skip to content

Commit 2e21aa9

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents c018800 + 4bf1ac4 commit 2e21aa9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+398
-12
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: Conditional Link
3+
sidebar_position: 11
4+
---
5+
6+
You can use the `conditional-link` component to render `<a>` tags conditionally. This can be useful if you want to link to something only if a user has the permission to do so.
7+
8+
## Basic usage
9+
10+
```bladehtml
11+
<x-forms::conditional-link :url="route('admin.users.index', $organization)" :show-link="$your_condition_boolean" value="10" />
12+
```
13+
14+
## Using `can`
15+
16+
Instead of directly using the `show-link` prop, you can also check for a user permission by using the `can` and `arg` props.
17+
18+
```bladehtml
19+
<x-forms::conditional-link :url="route('admin.users.index', $organization)" can="view" arg="users" value="10" />
20+
```
21+
22+
You can also specify a specific `guard` when using `can`
23+
24+
```bladehtml
25+
<x-forms::conditional-link :url="route('admin.users.index', $organization)" can="view" arg="users" guard="web" value="10" />
26+
```
27+
28+
## Using slot
29+
30+
You can also render your data manually instead of using the `value` prop.
31+
32+
```bladehtml
33+
<x-forms::conditional-link :url="route('admin.users.index', $organization)" can="view" arg="users">
34+
{{ $organization->users_count }}
35+
</x-forms::conditional-link>
36+
```
37+
38+
## Using model value binding
39+
40+
You can also bind to a model attribute value by using `name` prop when in a model context.
41+
42+
```bladehtml
43+
@model($organization)
44+
<x-forms::conditional-link :url="route('admin.users.index', $organization)" can="view" arg="users" name="users_count" />
45+
@endmodel
46+
```
47+
48+
## Passing additional HTML attributes
49+
50+
HTML attributes will get rendered on the `a` tag. For example, to set the `target` to `_blank`, just use the `target` attribute.
51+
Remember, if the `show-link` evaluates to `false`, then these extra attributes won't be rendered.
52+
53+
```bladehtml
54+
<x-forms::conditional-link :url="route('admin.users.index', $organization)" can="view" arg="users" value="10" target="_blank" />
55+
```
56+
57+
## Allowed props
58+
59+
The `conditional-link` support the following props:
60+
- `'url'` - (Required) the url to link to.
61+
- `'show-link'` - (Bool) Whether to render as a link or not
62+
- `'value'` - (Optional) Value to render in the link
63+
- `'name'` - Name of the attribute, if using model value binding
64+
- `'can'` - Ability to check for, instead of using `show-link`
65+
- `'arg'` - Argument to pass to `can` method
66+
- `'guard'` - User guard to use when using `can`. By default uses the current guard.
67+
- `'multiline'` - (Bool) If the bound value should be rendered as multiline
68+
- `framework` - Which css framework to use.

docs/basic-usage/select2.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ This would add `data-minimum-results-for-search="Infinity"` to the select elemen
4343

4444
# Enabling tags
4545

46-
To enable the user to add their own options to the select, enable the `tags` feature of Select2 by using the `tags` attribute.
46+
To enable the user to add their own options to the select, enable the `tags` feature of Select2 by using the `tags` attribute.
47+
When you use the `tags` option, any old values will automatically get added to the options if there's a validation error.
4748

4849
```html
4950
<x-forms::select2 name="categories" :options="$options" multiple tags />

resources/views/bootstrap-5/checkbox.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,9 @@ class="form-check-label"
2929
@if($hasErrorAndShow($name))
3030
<x-forms::errors :framework="$framework" :name="$name" />
3131
@endif
32+
33+
@if($showJsErrors)
34+
<x-forms::js-errors :framework="$framework" :name="$name" />
35+
@endif
3236
</x-forms::form-group>
3337

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@if($showLink)
2+
<a {{ $attributes->merge([
3+
'href' => $url
4+
]) }}>
5+
@endif
6+
@if($slot->isNotEmpty())
7+
{{ $slot }}
8+
@elseif($isAdminModel())
9+
{{ $value->admin_link_name }}
10+
@else
11+
@if($isStatusEnum())
12+
<x-forms::status :framework="$framework" :color="$value->getColor()" :label="$getEnumLabel()" />
13+
@elseif($multiline)
14+
{!! nl2br(e($value ?: trans('forms::strings.blank'))) !!}
15+
@elseif(is_array($value))
16+
{{ implode(trans('forms::strings.table_array_separator'), $value) }}
17+
@else
18+
{{ $formatValue() }}
19+
@endif
20+
@endif
21+
@if($showLink)
22+
</a>
23+
@endif
24+

resources/views/bootstrap-5/file.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@
7070
@if($hasErrorAndShow($name))
7171
<x-forms::errors :framework="$framework" :name="$name" />
7272
@endif
73+
74+
@if($showJsErrors)
75+
<x-forms::js-errors :framework="$framework" :name="$name" />
76+
@endif
7377
</x-forms::form-group>

resources/views/bootstrap-5/image.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,8 @@
8787
@if($hasErrorAndShow($name))
8888
<x-forms::errors :framework="$framework" :name="$name" />
8989
@endif
90+
91+
@if($showJsErrors)
92+
<x-forms::js-errors :framework="$framework" :name="$name" />
93+
@endif
9094
</x-forms::form-group>

resources/views/bootstrap-5/input.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,8 @@ class="{{ $clearBtnClass }}" title="{{ __('Clear') }}">
6060
@if($hasErrorAndShow($name))
6161
<x-forms::errors :framework="$framework" :name="$name"/>
6262
@endif
63+
64+
@if($showJsErrors)
65+
<x-forms::js-errors :framework="$framework" :name="$name" />
66+
@endif
6367
</x-forms::form-group>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<ul {!! $attributes->merge(['class' => 'invalid-feedback ' . $name . '-error']) !!}>
2+
{{ $slot }}
3+
</ul>

resources/views/bootstrap-5/map-input.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class="map-selector-radius"
7878
@if($hasErrorAndShow($name))
7979
<x-forms::errors :framework="$framework" :name="$name" />
8080
@endif
81+
82+
@if($showJsErrors)
83+
<x-forms::js-errors :framework="$framework" :name="$name" />
84+
@endif
8185
</x-forms::form-group>
8286

8387
@pushonce(config('forms.scripts_stack'))

resources/views/bootstrap-5/radio.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ class="form-check-label"
2929
@if($hasErrorAndShow($name))
3030
<x-forms::errors :framework="$framework" :name="$name" />
3131
@endif
32+
33+
@if($showJsErrors)
34+
<x-forms::js-errors :framework="$framework" :name="$name" />
35+
@endif
3236
</x-forms::form-group>

0 commit comments

Comments
 (0)