Skip to content

Instantly share code, notes, and snippets.

@mikhailkozlov
Created March 21, 2016 22:05
Show Gist options
  • Save mikhailkozlov/338b6d1d1d523c32fe44 to your computer and use it in GitHub Desktop.
Save mikhailkozlov/338b6d1d1d523c32fe44 to your computer and use it in GitHub Desktop.
spark
<?php
namespace App\Providers;
use App\Models\Account;
use Validator;
use Laravel\Spark\Spark;
use Illuminate\Http\Request;
use Laravel\Spark\Providers\AppServiceProvider as ServiceProvider;
class SparkServiceProvider extends ServiceProvider
{
protected $twoFactorAuth = false;
/**
* Meta-data included in invoices generated by Spark.
*
* @var array
*/
protected $invoiceWith = [
'vendor' => '',
'product' => '',
'street' => '',
'location' => '',
'phone' => '555-555-5555',
];
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
parent::boot();
//
}
/**
* Customize general Spark options.
*
* @return void
*/
protected function customizeSpark()
{
Spark::configure([
'models' => [
'teams' => Account::class,
]
]);
}
/**
* Customize Spark's new user registration logic.
*
* @return void
*/
protected function customizeRegistration()
{
Spark::validateRegistrationsWith(function (Request $request) {
// fudge name for OOB validation
$request->request->set('name', $request->first_name . ' ' . $request->last_name);
// in case we have limited plans to one, we need to set it to user's name
$plan = Spark::plans()->find($request->plan);
if ($plan->attributes()['limitTeams'] === 1) {
$request->request->set('team_name', $request->first_name . ' ' . $request->last_name);
}
return [
'last_name' => 'required|max:255',
'first_name' => 'required|max:255',
'email' => 'required|email|unique:users',
'password' => 'required|confirmed|min:6',
'terms' => 'required|accepted',
];
});
Spark::createUsersWith(function (Request $request) {
$model = config('auth.model');
return (new $model)->create([
'first_name' => $request->first_name,
'last_name' => $request->last_name,
'email' => $request->email,
'password' => bcrypt($request->password),
]);
});
}
/**
* Customize the roles that may be assigned to team members.
*
* @return void
*/
protected function customizeRoles()
{
Spark::defaultRole('member');
Spark::roles([
'admin' => 'Administrator',
'member' => 'Member',
'renter' => 'Renter',
]);
}
/**
* Customize the tabs on the settings screen.
*
* @return void
*/
protected function customizeSettingsTabs()
{
Spark::settingsTabs()->configure(function ($tabs) {
return [
$tabs->profile(),
$tabs->make('My Companies', 'spark::settings.tabs.teams', 'fa-users', function () {
return Spark::usingTeams();
}),
// $tabs->teams(),
$tabs->security(),
$tabs->subscription(),
];
});
Spark::teamSettingsTabs()->configure(function ($tabs) {
return [
$tabs->owner(),
$tabs->membership(),
$tabs->make('Reservation Portal', 'system.settings.tabs.site', 'fa-hotel'),
];
});
}
/**
* Customize Spark's profile update logic.
*
* @return void
*/
protected function customizeProfileUpdates()
{
// Spark::validateProfileUpdatesWith(function (Request $request) {
// return [
// 'name' => 'required|max:255',
// 'email' => 'required|email|unique:users,email,'.$request->user()->id,
// ];
// });
// Spark::updateProfilesWith(function (Request $request) {
// // Update $request->user()...
// });
}
/**
* Customize the subscription plans for the application.
*
* @return void
*/
protected function customizeSubscriptionPlans()
{
Spark::free('Owner')
->features([
'Single Property',
'Single User',
'All other features',
'&nbsp;',
'&nbsp;',
])
->attributes([
'limitTeams' => 1,
'limitProperties' => 1,
]);
Spark::plan('Manager', 'ocr_maneger')->price(50)
->trialDays(7)
->features([
'Up 50 Properties',
'5 Agents',
'All other features',
'Integration with Barefoot',
'&nbsp;',
])
->attributes([
'limitTeams' => 1,
'limitProperties' => 50,
]);
Spark::plan('Company', 'ocr-company')->price(100)
->trialDays(7)
->features([
'Unlimited Properties',
'Unlimited Agents',
'All other features',
'Integration with Barefoot',
'Reports',
])
->attributes([
'limitTeams' => false,
'limitProperties' => false,
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment