|
| 1 | +# Store and handle devices connecting to your web application |
| 2 | + |
| 3 | +[](https://packagist.org/packages/coreproc/laravel-devices) |
| 4 | +[](https://scrutinizer-ci.com/g/coreproc/laravel-devices) |
| 5 | +[](https://packagist.org/packages/coreproc/laravel-devices) |
| 6 | + |
| 7 | +This package sets up the database and middleware needed in storing devices. This is perfect for handling mobile devices |
| 8 | +using your web API. You'll be able to identify each device, assign them an FCM token, and relate them to users as well. |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +You can install the package via composer: |
| 13 | + |
| 14 | +```bash |
| 15 | +composer require coreproc/laravel-devices |
| 16 | +``` |
| 17 | + |
| 18 | +You must publish the migration with: |
| 19 | + |
| 20 | +```bash |
| 21 | +php artisan vendor:publish --provider="Coreproc\Devices\DevicesServiceProvider" --tag="migrations" |
| 22 | +``` |
| 23 | + |
| 24 | +Migrate the statuses table: |
| 25 | + |
| 26 | +```bash |
| 27 | +php artisan migrate |
| 28 | +``` |
| 29 | + |
| 30 | +Optionally you can publish the config file with: |
| 31 | + |
| 32 | +```bash |
| 33 | +php artisan vendor:publish --provider="Coreproc\Devices\DevicesServiceProvider" --tag="config" |
| 34 | +``` |
| 35 | + |
| 36 | +## Usage |
| 37 | + |
| 38 | +To begin storing device information, you can attach the `store.device` middleware to any of your routes. Here is an |
| 39 | +example: |
| 40 | + |
| 41 | +```php |
| 42 | +// routes/api.php |
| 43 | + |
| 44 | +Route::middleware('store.device')->get('/test', function (Request $request) { |
| 45 | + return []; |
| 46 | +}); |
| 47 | +``` |
| 48 | + |
| 49 | +Now, when you use the API endpoint `/api/test`, you can attach the device information to the header. Here is a complete |
| 50 | +list of data that you can enter: |
| 51 | + |
| 52 | +```bash |
| 53 | +curl --request GET \ |
| 54 | + --url http://devices.test/api/test \ |
| 55 | + --header 'x-device-app-version: 1.0.1' \ |
| 56 | + --header 'x-device-fcm-token: firebase-cloud-messaging-token' \ |
| 57 | + --header 'x-device-manufacturer: Samsung' \ |
| 58 | + --header 'x-device-model: Galaxy S10' \ |
| 59 | + --header 'x-device-os: Android' \ |
| 60 | + --header 'x-device-os-version: 8.0' \ |
| 61 | + --header 'x-device-udid: unique-device-udid' |
| 62 | +``` |
| 63 | + |
| 64 | +This will store all of the above information to the database. Only the `x-device-udid` header field is required. |
| 65 | + |
| 66 | +If a user is authenticated, it will relate the user to this device automatically. |
| 67 | + |
| 68 | +You can define the guard to be used in the first parameter of the middleware. |
| 69 | + |
| 70 | +```php |
| 71 | +// routes/api.php |
| 72 | + |
| 73 | +Route::middleware('store.device:web')->get('/test', function (Request $request) { |
| 74 | + return []; |
| 75 | +}); |
| 76 | +``` |
| 77 | + |
| 78 | +You can define if the device should be required or not in the second parameter, delimted by a comma. |
| 79 | + |
| 80 | +```php |
| 81 | +// routes/api.php |
| 82 | + |
| 83 | +Route::middleware('store.device:web,0')->get('/test', function (Request $request) { |
| 84 | + return []; |
| 85 | +}); |
| 86 | +``` |
| 87 | + |
| 88 | +### Changelog |
| 89 | + |
| 90 | +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. |
| 91 | + |
| 92 | +## Contributing |
| 93 | + |
| 94 | +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 95 | + |
| 96 | +### Security |
| 97 | + |
| 98 | +If you discover any security related issues, please email [email protected] instead of using the issue tracker. |
| 99 | + |
| 100 | +## About CoreProc |
| 101 | + |
| 102 | +CoreProc is a software development company that provides software development services to startups, digital/ad agencies, and enterprises. |
| 103 | + |
| 104 | +Learn more about us on our [website](https://coreproc.com). |
| 105 | + |
| 106 | +## Credits |
| 107 | + |
| 108 | +- [Chris Bautista](https://github.com/chrisbjr) |
| 109 | +- [All Contributors](../../contributors) |
| 110 | + |
| 111 | +## License |
| 112 | + |
| 113 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
0 commit comments