zvermafia / alif-api-wrapper-for-laravel
Integration of the zvermafia/alif-api-wrapper with Lavel
Requires
- php: >=7.1.3
- laravel/framework: ~5.4||~5.5||~5.6||~5.7||~5.8
- zvermafia/alif-api-wrapper: ^1.0
Requires (Dev)
- phpunit/phpunit: ^7.0
- squizlabs/php_codesniffer: ^2.3
README
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.