Permalink
Browse files

Subscription Plans and Features

  • Loading branch information...
bpocallaghan committed Jul 5, 2017
1 parent 8552c56 commit 0dd94dce18f10170eb6c89e976e467a285bfbebe
Showing with 958 additions and 59 deletions.
  1. +1 −0 README.md
  2. +1 −1 app/Http/Controllers/Admin/Settings/Admin/AdministratorsController.php
  3. +94 −0 app/Http/Controllers/Admin/Settings/Website/FeaturesController.php
  4. +190 −0 app/Http/Controllers/Admin/Settings/Website/SubscriptionPlansController.php
  5. +4 −2 app/Http/Controllers/Website/PagesController.php
  6. +37 −0 app/Models/SubscriptionPlan.php
  7. +41 −0 app/Models/SubscriptionPlanFeature.php
  8. +38 −0 database/migrations/2017_07_04_175040_create_subscription_plans_table.php
  9. +35 −0 database/migrations/2017_07_04_175120_create_subscription_plan_features_table.php
  10. +38 −0 ...e/migrations/2017_07_05_094620_create_subscription_plan_feature_subscription_plan_pivot_table.php
  11. +3 −0 database/seeds/DatabaseSeeder.php
  12. +24 −0 database/seeds/SubscriptionPlanFeaturesSeeder.php
  13. +39 −0 database/seeds/SubscriptionPlanTableSeeder.php
  14. +1 −0 database/seeds/csv/navigation_admin.csv
  15. +16 −0 database/seeds/csv/subscription_plan_features.csv
  16. +4 −0 database/seeds/csv/subscription_plans.csv
  17. +11 −0 resources/views/admin/dashboard.blade.php
  18. +2 −0 resources/views/admin/settings/admin/users/administrators.blade.php
  19. +74 −0 resources/views/admin/settings/website/subscription_plans/add_edit.blade.php
  20. +41 −0 resources/views/admin/settings/website/subscription_plans/features/add_edit.blade.php
  21. +42 −0 resources/views/admin/settings/website/subscription_plans/features/index.blade.php
  22. +45 −0 resources/views/admin/settings/website/subscription_plans/features_order.blade.php
  23. +66 −0 resources/views/admin/settings/website/subscription_plans/index.blade.php
  24. +74 −0 resources/views/admin/settings/website/subscription_plans/show.blade.php
  25. +31 −56 resources/views/website/pricing.blade.php
  26. +6 −0 routes/web.php
@@ -11,6 +11,7 @@ A Laravel CMS Starter project with AdminLTE theme and core features.
### What is New?
- [Impersonation](https://github.com/bpocallaghan/impersonate) When logged in, [go here](http://bpocallaghan.co.za/admin/settings/admin/users) and click on the 'impersonate user' action.
- Roles (Assign a role to user and assign role to navigation. Can only see navigation for given role)
- Subscription Plans (Manage the Subscription Plans and Features)
## Features / What it includes
- Admin LTE admin theme
@@ -21,7 +21,7 @@ public function index()
{
save_resource_url();
$items = User::all();
$items = User::with('roles')->get();
$this->resource = 'Administrator';
@@ -0,0 +1,94 @@
<?php
namespace App\Http\Controllers\Admin\Settings\Website;
use Redirect;
use App\Http\Requests;
use Illuminate\Http\Request;
use App\Models\SubscriptionPlanFeature;
use App\Http\Controllers\Admin\AdminController;
class FeaturesController extends AdminController
{
/**
* Display a listing of subscription_plan.
*
* @return Response
*/
public function index()
{
save_resource_url();
return $this->view('settings.website.subscription_plans.features.index')
->with('items', SubscriptionPlanFeature::all());
}
/**
* Show the form for creating a new subscription_plan.
*
* @return Response
*/
public function create()
{
return $this->view('settings.website.subscription_plans.features.add_edit');
}
/**
* Store a newly created subscription_plan in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, SubscriptionPlanFeature::$rules,
SubscriptionPlanFeature::$messages);
$this->createEntry(SubscriptionPlanFeature::class, $request->only('title'));
return redirect_to_resource();
}
/**
* Show the form for editing the specified subscription_plan.
*
* @param SubscriptionPlanFeature $feature
* @return Response
*/
public function edit(SubscriptionPlanFeature $feature)
{
return $this->view('settings.website.subscription_plans.features.add_edit')
->with('item', $feature);
}
/**
* Update the specified subscription_plan in storage.
*
* @param SubscriptionPlanFeature $feature
* @param Request $request
* @return Response
*/
public function update(SubscriptionPlanFeature $feature, Request $request)
{
$this->validate($request, SubscriptionPlanFeature::$rules,
SubscriptionPlanFeature::$messages);
$this->updateEntry($feature, $request->only('title'));
return redirect_to_resource();
}
/**
* Remove the specified subscription_plan from storage.
*
* @param SubscriptionPlanFeature $feature
* @param Request $request
* @return Response
*/
public function destroy(SubscriptionPlanFeature $feature, Request $request)
{
$this->deleteEntry($feature, $request);
return redirect_to_resource();
}
}
@@ -0,0 +1,190 @@
<?php
namespace App\Http\Controllers\Admin\Settings\Website;
use App\Models\SubscriptionPlanFeature;
use Redirect;
use App\Http\Requests;
use App\Models\SubscriptionPlan;
use Illuminate\Http\Request;
use App\Http\Controllers\Admin\AdminController;
class SubscriptionPlansController extends AdminController
{
/**
* Display a listing of subscription_plan.
*
* @return Response
*/
public function index()
{
save_resource_url();
return $this->view('settings.website.subscription_plans.index')
->with('items', SubscriptionPlan::all());
}
/**
* Show the form for creating a new subscription_plan.
*
* @return Response
*/
public function create()
{
$features = SubscriptionPlanFeature::getAllList();
return $this->view('settings.website.subscription_plans.add_edit')
->with('features', $features);
}
/**
* Store a newly created subscription_plan in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, SubscriptionPlan::$rules, SubscriptionPlan::$messages);
if (!$request->has('is_featured')) {
$request->merge(['is_featured' => false]);
}
else {
$request->merge(['is_featured' => true]);
}
$subscriptionPlan = $this->createEntry(SubscriptionPlan::class,
$request->only('is_featured', 'title', 'cost', 'summary'));
if ($subscriptionPlan) {
$subscriptionPlan->features()->sync(input('features'));
}
return redirect_to_resource();
}
/**
* Display the specified subscription_plan.
*
* @param SubscriptionPlan $subscription_plan
* @return Response
*/
public function show(SubscriptionPlan $subscription_plan)
{
return $this->view('settings.website.subscription_plans.show')
->with('item', $subscription_plan);
}
/**
* Show the form for editing the specified subscription_plan.
*
* @param SubscriptionPlan $subscription_plan
* @return Response
*/
public function edit(SubscriptionPlan $subscription_plan)
{
$features = SubscriptionPlanFeature::getAllList();
return $this->view('settings.website.subscription_plans.add_edit')
->with('item', $subscription_plan)
->with('features', $features);
}
/**
* Update the specified subscription_plan in storage.
*
* @param SubscriptionPlan $subscription_plan
* @param Request $request
* @return Response
*/
public function update(SubscriptionPlan $subscription_plan, Request $request)
{
$this->validate($request, SubscriptionPlan::$rules, SubscriptionPlan::$messages);
if (!$request->has('is_featured')) {
$request->merge(['is_featured' => false]);
}
else {
$request->merge(['is_featured' => true]);
}
$subscriptionPlan = $this->updateEntry($subscription_plan,
$request->only('is_featured', 'title', 'cost', 'summary'));
if ($subscriptionPlan) {
$subscriptionPlan->features()->sync(input('features'));
}
return redirect_to_resource();
}
/**
* Remove the specified subscription_plan from storage.
*
* @param SubscriptionPlan $subscription_plan
* @param Request $request
* @return Response
*/
public function destroy(SubscriptionPlan $subscription_plan, Request $request)
{
$this->deleteEntry($subscription_plan, $request);
return redirect_to_resource();
}
/**
* Show the Subscription Plan Features
* @param SubscriptionPlan $subscription_plan
* @return mixed
*/
public function showFeaturesOrder(SubscriptionPlan $subscription_plan)
{
$html = $this->getFeaturesListOrderHtml($subscription_plan);
return $this->view('settings.website.subscription_plans.features_order')
->with('itemsHtml', $html);
}
/**
* Update the list order for the features
* @param SubscriptionPlan $subscription_plan
* @param Request $request
* @return array
*/
public function updateFeaturesOrder(SubscriptionPlan $subscription_plan, Request $request)
{
$items = json_decode($request->get('list'), true);
$features = [];
foreach ($items as $key => $item) {
$features[$item['id']] = ['list_order' => ($key + 1)];
}
$subscription_plan->features()->syncWithoutDetaching($features);
return ['result' => 'success'];
}
/**
* Generate the nestable html
*
* @param SubscriptionPlan $subscription_plan
* @return string
* @internal param null $parent
*
*/
private function getFeaturesListOrderHtml(SubscriptionPlan $subscription_plan)
{
$html = '<ol class="dd-list">';
$items = $subscription_plan->features;
foreach ($items as $key => $item) {
$html .= '<li class="dd-item" data-id="' . $item->id . '">';
$html .= '<div class="dd-handle">' . $item->title . '</div>';
$html .= '</li>';
}
$html .= '</ol>';
return (count($items) >= 1 ? $html : '');
}
}
@@ -3,10 +3,10 @@
namespace App\Http\Controllers\Website;
use App\Http\Requests;
use App\Models\SubscriptionPlan;
class PagesController extends WebsiteController
{
public function column1()
{
return $this->view('column_1');
@@ -34,6 +34,8 @@ public function column4()
*/
public function pricing()
{
return $this->view('pricing');
$subscriptionPlans = SubscriptionPlan::with('features')->get();
return $this->view('pricing', compact('subscriptionPlans'));
}
}
@@ -0,0 +1,37 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Titan\Models\TitanCMSModel;
class SubscriptionPlan extends TitanCMSModel
{
use SoftDeletes;
protected $table = 'subscription_plans';
protected $guarded = ['id'];
/**
* Validation rules for this model
*/
static public $rules = [
'title' => 'required|min:3:max:255',
'cost' => 'required|min:1:max:255',
];
public function getFeaturesStringAttribute()
{
return implode(', ', $this->features()->get()->pluck('title', 'id')->toArray());
}
/**
* Get the SubscriptionPlanFeature many to many
*/
public function features()
{
return $this->belongsToMany(SubscriptionPlanFeature::class, 'subscription_plan_feature_pivot')->orderBy('list_order');
}
}
Oops, something went wrong.

0 comments on commit 0dd94dc

Please sign in to comment.