monthly-cloud / monthly-sdk-laravel
Laravel SDK for monthly.cloud.
Installs: 2 868
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 1
Open Issues: 0
Requires
- php: >=7.0
- illuminate/support: 5.*||6.*||7.*||8.*||9.*||10.*
- monthly-cloud/monthly-sdk-php: ^0.8.2
Requires (Dev)
- orchestra/testbench: ^4.0
- phpunit/phpunit: ^7.0|^8.0|^9.0|^10.0
README
Laravel SDK used to connect with monthly cloud.
Installation
composer require monthly-cloud/monthly-sdk-laravel
Add Monthly Cloud service provider and alias to your config/app.php config:
'providers' => [ ... MonthlyCloud\Laravel\MonthlyCloudServiceProvider::class, ],
'aliases' => [ ... 'MonthlyCloud' => MonthlyCloud\Laravel\MonthlyCloud::class, 'MonthlyStorage' => MonthlyCloud\Laravel\MonthlyStorage::class, ],
Configuration
To create configuration file run:
php artisan vendor:publish --provider="MonthlyCloud\Laravel\MonthlyCloudServiceProvider"
In oprder to access cloud API update .env file MONTHLY_CLOUD_ACCESS_TOKEN
variable or config/monthlycloud.php
access_token with access token generated in cloud settings.
To use Monthly Storage set MONTHLY_CLOUD_WEBSITE_ID
and MONTHLY_CLOUD_LISTING_ID
.
Usage
Example usage of Monthly Cloud sdk:
$property = MonthlyCloud::endpoint('properties')->find(1); // Single property $properties = MonthlyCloud::endpoint('properties')->get(); // List of properties
Example usage of Monthly Storage sdk:
MonthlyStorage::endpoint('routes')->get(); // get routes using default app language MonthlyStorage::endpoint('menus')->locale('en')->get(); // get menus in pre-defined language MonthlyStorage::endpoint('contents')->find(31); // find content MonthlyStorage::endpoint('contents')->website(3)->id(31)->buildUrl(); // build file url for specific website and content id MonthlyStorage::getListingItem()->find(100); // find listing item MonthlyStorage::findContent(1); // quick way to find content MonthlyStorage::getRoutes('en'); // quick way to access routes
Example usage of Translation Service:
/** * Get key from translations dictionary. * * @param string|null $key * @return string|array */ function __t($key = null) { if (empty($key)) { return app(\MonthlyCloud\Laravel\Services\TranslationService::class)->getTranslations(); } return app(\MonthlyCloud\Laravel\Services\TranslationService::class)->translate($key); }
User log-in
Monthly Cloud is compatible with Laravel Authentication.
You can setup authentication by running:
php artisan make:auth
php artisan migrate
Setup cloud provider in auth.php:
'guards' => [
'web' => [
...
'provider' => 'cloud',
],
...
'providers' => [
'cloud' => [
'driver' => 'cloud',
'model' => App\User::class,
],
...
],
Add IsMonthlyCloudUser trait to User model. By default it will store cloud "label" in $user->name and save it in database.
If you need more information in local database check applyUserData
method in IsMonthlyCloudUser
trait.