Skip to content

Commit 795f6ca

Browse files
committed
model key for reference is now customizable
1 parent c623e5e commit 795f6ca

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

config/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
'references-nullable' => true,
131131
/*
132132
* Ether you define your models for references or customize the view.
133+
* Example: [App/Models/User::class]
133134
*/
134135
'reference-models' => []
135136
];

resources/views/tickets/create.blade.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747
@if (!$model->hasReferenceAccess())
4848
@continue
4949
@endif
50-
<option value="{{ $model->toReference() }}"
51-
@if (old('reference') === $model->toReference())
52-
selected
53-
@endif>@lang(basename(get_class($model))) #{{$model->id}}</option>
50+
<option
51+
value="{{ $modelReference = \RexlManu\LaravelTickets\Helper\ReferenceHelper::modelToReference($model) }}"
52+
@if (old('reference') === $modelReference)
53+
selected
54+
@endif>{{ $model->toReference() }}</option>
5455
@endforeach
5556
@endforeach
5657
</select>

resources/views/tickets/show.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class="custom-file-input @error('files') is-invalid @enderror" id="files">
9292
<label>@lang('Reference'):</label>
9393
@php($referenceable = $ticket->reference->referenceable)
9494
<input class="form-control" type="text"
95-
value="@lang(basename(get_class($referenceable))) #{{$referenceable->id}}" disabled>
95+
value="{{ $referenceable->toReference() }}" disabled>
9696
</div>
9797
@endif
9898
<div class="form-group">

src/Helper/ReferenceHelper.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
4+
namespace RexlManu\LaravelTickets\Helper;
5+
6+
7+
class ReferenceHelper
8+
{
9+
10+
public static function modelToReference($model) : string
11+
{
12+
$type = get_class($model);
13+
return "$type,$model->id";
14+
}
15+
16+
17+
}

src/Interfaces/TicketReference.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface TicketReference
1515
function hasReferenceAccess() : bool;
1616

1717
/**
18-
* Combine type and id to a string for forms
18+
* Show the name when on selection
1919
*
2020
* @return string
2121
*/

src/Traits/HasTicketReference.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ trait HasTicketReference
99

1010
public function toReference() : string
1111
{
12-
$type = get_class($this);
13-
return "$type,$this->id";
12+
$type = basename(get_class($this));
13+
return "$type #$this->id";
1414
}
1515

1616
}

0 commit comments

Comments
 (0)