frontend & backend update

This commit is contained in:
carodej
2020-06-22 16:46:02 +02:00
parent a2cab6198e
commit a2dfc627a7
35 changed files with 595 additions and 1080 deletions

View File

@@ -11,6 +11,7 @@ use App\Plan;
use App\Services\StripeService;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Rinvex\Subscriptions\Models\PlanFeature;
class PlanController extends Controller
@@ -30,9 +31,18 @@ class PlanController extends Controller
*/
public function index()
{
return new PlanCollection(
$this->stripe->getPlans()
);
// Store or Get plans to cache
if (Cache::has('plans')) {
$plans = Cache::get('plans');
} else {
$plans = Cache::rememberForever('plans', function () {
return $this->stripe->getPlans();
});
}
return new PlanCollection($plans);
}
/**
@@ -43,9 +53,18 @@ class PlanController extends Controller
*/
public function show($id)
{
return new PlanResource(
$this->stripe->getPlan($id)
);
// Store or Get plan to cache
if (Cache::has('plan-' . $id)) {
$plan = Cache::get('plan-' . $id);
} else {
$plan = Cache::rememberForever('plan-' . $id, function () use ($id) {
return $this->stripe->getPlan($id);
});
}
return new PlanResource($plan);
}
/**
@@ -56,9 +75,14 @@ class PlanController extends Controller
*/
public function store(Request $request)
{
return new PlanResource(
$plan = new PlanResource(
$this->stripe->createPlan($request)
);
// Clear cached plans
cache_forget_many(['plans', 'pricing']);
return $plan;
}
/**
@@ -72,6 +96,9 @@ class PlanController extends Controller
{
$this->stripe->updatePlan($request, $id);
// Clear cached plans
cache_forget_many(['plans', 'pricing', 'plan-' . $id]);
return response('Saved!', 204);
}
@@ -85,6 +112,9 @@ class PlanController extends Controller
{
$this->stripe->deletePlan($id);
// Clear cached plans
cache_forget_many(['plans', 'pricing']);
return response('Done!', 204);
}