Skip to content

Latest commit

 

History

History
64 lines (53 loc) · 2.18 KB

content-suggestions.md

File metadata and controls

64 lines (53 loc) · 2.18 KB

Content suggestion

DHL API requires to provide shipment contents. This package has helper for content suggestions.

Add content suggestion

If you want to add content suggestion use facade method:

xGrz\Dhl24\Facades\DHL24::contentSuggestions()->add($name);

There is no limit for suggestions.

This method can throw DHL24Exception when name is not unique!


Suggestions listing (query)

xGrz\Dhl24\Facades\DHL24::contentSuggestions()->query()->sortedByNames(): Builder;

This method return query builder for content suggestions. You can use all eloquent query builder methods. It allows to add pagination or filtering results. Typically, you will sort your results by name or by is_default. You can use predefined scopes sortedByNames on query or defaultFirst. If you want to combine them use defaultFirst before sortedByNames to get default cost center as first on list.


Rename suggestion

If you want to modify suggestion name you can use:

xGrz\Dhl24\Facades\DHL24::contentSuggestions($suggestion)->rename($name);

First parameter suggestion can be eider xGrz\Dhl24\Models\DHLContentSuggestion or id of suggestion. Second parameter name should be new name of suggestions.

This method can throw DHL24Exception when name is not unique!


Delete suggestion

xGrz\Dhl24\Facades\DHL24::contentSuggestions($suggestion)->delete();

Parameter suggestion can be eider xGrz\Dhl24\Models\DHLContentSuggestion or id of suggestion to delete. This model deletes permanently database row. Soft delete is not implemented here.


How to use it?

You can provide suggestions list as select if you don't allow users providing own contents.

<select>
    @foreach(\xGrz\Dhl24\Facades\DHL24::contentSuggestions()->query()->get() as $suggestion)
        <option>{{$suggestion->name}}</option>
    @endforeach
</select>

If user can provide own content the best way is to use datalist related to input:

<input list="contents"/>
<datalist id="contents">
    @foreach(\xGrz\Dhl24\Facades\DHL24::contentSuggestions()->query()->get() as $suggestion)
        <option value="{{$suggestion->name}}"/>
    @endforeach
</datalist>