zvermafia/alif-api-wrapper-for-laravel

This package is abandoned and no longer maintained. The author suggests using the zvermafia/transliteration-laravel package instead.

Integration of the zvermafia/alif-api-wrapper with Lavel

1.0.1 2019-07-25 20:16 UTC

This package is auto-updated.

Last update: 2020-03-25 14:46:26 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Please instead of this use a zvermafia/transliteration-laravel, this repository will be deleted on 2021

Integration of the zvermafia/alif-api-wrapper with Laravel.

Navigation by sections

Install

Via Composer

$ composer require zvermafia/alif-api-wrapper-for-laravel

Setup

You can skip this step if you have Laravel >= 5.5. Cause there is a Package Discovery. Open config/app.php and find the providers key. Add the service provider to the array.

Zvermafia\LaraTransliteration\LaraTransliterationServiceProvider::class

You can also add an alias to the list of class aliases in the same file.

'LaraTransliterator' => Zvermafia\LaraTransliteration\Facades\LaraTransliteratorFacade::class

Usage

Let's example we have a TestController with a store method in which we want to store a transliterated text.

// ...
use LaraTransliterator;
// ...
    public function store(Request $request)
    {
        $response = LaraTransliterator::setText($request->input('text'))
            ->toCyrillic() // or you can use ->toLatin()
            ->translit();

        $transliterated_text = $response->getResult();
    }
// ...

For AJAX requests you can use a ready-made controller! Firstly you must define routes for the controller:

// in your routes file
Route::post('translit/to-cyrillic', '\Zvermafia\LaraTransliteration\Controllers\TransliteratorController@toCyrillic')->name('translit.to_cyrillic');
Route::post('translit/to-latin', '\Zvermafia\LaraTransliteration\Controllers\TransliteratorController@toLatin')->name('translit.to_latin');

For AJAX request demonstration we'll use jQuery library:

$.ajax({
    url: '/translit/cyrillic',
    type: 'POST',
    data: {
        // _token: $('meta[name="csrf-token"]').attr('content'),
        text: 'Salom, dunyo!'
    },
    dataType: 'JSON'
})
.done(function (response) {
    if (response.code === 200) {
        alert(response.text);
    } else {
        alert('Something went wrong... Check the console log:');
        console.log(response);
    }
})
.fail(function (response) {
    console.log('Whoops, something went wrong... Check the response below:');
    console.log(response);
});
// A response will be like below:
{
    "code": 200,
    "text": "Transliterated text"
} 

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email mohirjon@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.