Skip to content

Commit

Permalink
model key for reference is now customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
rexlManu committed Nov 19, 2020
1 parent c623e5e commit 795f6ca
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions config/config.php
Expand Up @@ -130,6 +130,7 @@
'references-nullable' => true,
/*
* Ether you define your models for references or customize the view.
* Example: [App/Models/User::class]
*/
'reference-models' => []
];
9 changes: 5 additions & 4 deletions resources/views/tickets/create.blade.php
Expand Up @@ -47,10 +47,11 @@
@if (!$model->hasReferenceAccess())
@continue
@endif
<option value="{{ $model->toReference() }}"
@if (old('reference') === $model->toReference())
selected
@endif>@lang(basename(get_class($model))) #{{$model->id}}</option>
<option
value="{{ $modelReference = \RexlManu\LaravelTickets\Helper\ReferenceHelper::modelToReference($model) }}"
@if (old('reference') === $modelReference)
selected
@endif>{{ $model->toReference() }}</option>
@endforeach
@endforeach
</select>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/tickets/show.blade.php
Expand Up @@ -92,7 +92,7 @@ class="custom-file-input @error('files') is-invalid @enderror" id="files">
<label>@lang('Reference'):</label>
@php($referenceable = $ticket->reference->referenceable)
<input class="form-control" type="text"
value="@lang(basename(get_class($referenceable))) #{{$referenceable->id}}" disabled>
value="{{ $referenceable->toReference() }}" disabled>
</div>
@endif
<div class="form-group">
Expand Down
17 changes: 17 additions & 0 deletions src/Helper/ReferenceHelper.php
@@ -0,0 +1,17 @@
<?php


namespace RexlManu\LaravelTickets\Helper;


class ReferenceHelper
{

public static function modelToReference($model) : string
{
$type = get_class($model);
return "$type,$model->id";
}


}
2 changes: 1 addition & 1 deletion src/Interfaces/TicketReference.php
Expand Up @@ -15,7 +15,7 @@ interface TicketReference
function hasReferenceAccess() : bool;

/**
* Combine type and id to a string for forms
* Show the name when on selection
*
* @return string
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/HasTicketReference.php
Expand Up @@ -9,8 +9,8 @@ trait HasTicketReference

public function toReference() : string
{
$type = get_class($this);
return "$type,$this->id";
$type = basename(get_class($this));
return "$type #$this->id";
}

}

0 comments on commit 795f6ca

Please sign in to comment.