mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 16:22:14 +00:00
frontend/backend update
This commit is contained in:
@@ -5,8 +5,12 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\PlanCollection;
|
||||
use App\Http\Resources\PlanResource;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Http\Resources\UsersCollection;
|
||||
use App\Plan;
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Rinvex\Subscriptions\Models\PlanFeature;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
@@ -15,9 +19,11 @@ class PlanController extends Controller
|
||||
*
|
||||
* @return PlanCollection
|
||||
*/
|
||||
public function index() {
|
||||
|
||||
return new PlanCollection(Plan::all());
|
||||
public function index()
|
||||
{
|
||||
return new PlanCollection(
|
||||
app('rinvex.subscriptions.plan')->all()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,9 +34,9 @@ class PlanController extends Controller
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$plan = Plan::findOrFail($id);
|
||||
|
||||
return new PlanResource($plan);
|
||||
return new PlanResource(
|
||||
app('rinvex.subscriptions.plan')->find($id)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,9 +47,24 @@ class PlanController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// TODO: validation request
|
||||
$plan = app('rinvex.subscriptions.plan')->create([
|
||||
'description' => $request->input('attributes.description'),
|
||||
'price' => $request->input('attributes.price'),
|
||||
'name' => $request->input('attributes.name'),
|
||||
'currency' => 'USD',
|
||||
'invoice_period' => 1,
|
||||
'sort_order' => 1,
|
||||
'signup_fee' => 0,
|
||||
]);
|
||||
|
||||
$plan = Plan::create($request->input('attributes'));
|
||||
// Create multiple plan features at once
|
||||
$plan->features()->saveMany([
|
||||
new PlanFeature([
|
||||
'name' => 'Storage capacity',
|
||||
'value' => $request->input('attributes.capacity'),
|
||||
'sort_order' => 1
|
||||
]),
|
||||
]);
|
||||
|
||||
return new PlanResource($plan);
|
||||
}
|
||||
@@ -58,11 +79,32 @@ class PlanController extends Controller
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
// TODO: validation request
|
||||
$plan = Plan::findOrFail($id);
|
||||
$plan = app('rinvex.subscriptions.plan')->find($id);
|
||||
|
||||
// Update text data
|
||||
$plan->update(make_single_input($request));
|
||||
if ($request->name === 'capacity') {
|
||||
$plan->getFeatureBySlug('storage-capacity')->update(['value' => $request->value]);
|
||||
} else {
|
||||
$plan->update(make_single_input($request));
|
||||
}
|
||||
|
||||
return response('Saved!', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subscriptions
|
||||
*
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function subscribers($id)
|
||||
{
|
||||
$subscribers = app('rinvex.subscriptions.plan')
|
||||
->find($id)
|
||||
->subscriptions
|
||||
->pluck('user_id');
|
||||
|
||||
return new UsersCollection(
|
||||
User::findMany($subscribers)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user