forked from eatvio/eatvio-infra
120 lines
2.7 KiB
PHP
120 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Plan;
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
|
|
class PlanController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
/* dd($request->get('author')); */
|
|
if ($request->has('author')) {
|
|
$author = $request->get('author');
|
|
$user = User::find($author);
|
|
$plans = $user ? $user->author_of_plans : [];
|
|
} else {
|
|
$plans = Plan::all();
|
|
}
|
|
|
|
return view('plan/index', ['plans' => $plans]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('plan/edit_form');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show(Plan $plan)
|
|
{
|
|
|
|
$expiresAt = now()->addHours(24);
|
|
|
|
views($plan)
|
|
->cooldown($expiresAt)
|
|
->record();
|
|
|
|
// $options1 = $this->unserializeOptions($plan->packet1_options);
|
|
// $options2 = $this->unserializeOptions($plan->packet2_options);
|
|
// $options3 = $this->unserializeOptions($plan->packet2_options);
|
|
// $options1 = $plan->packet1_options;
|
|
// $options2 = $plan->packet2_options;
|
|
// $options3 = $plan->packet2_options;
|
|
|
|
return view('plan/show',
|
|
[
|
|
'plan' => $plan,
|
|
// 'options1' => $options1,
|
|
// 'options2' => $options2,
|
|
// 'options3' => $options3,
|
|
]
|
|
);
|
|
}
|
|
|
|
private function unserializeOptions($str)
|
|
{
|
|
if (preg_match('/^".*"$/', $str)) {
|
|
return json_decode(stripslashes(mb_substr($str, 1, -1)), true);
|
|
}
|
|
|
|
return json_decode(stripslashes($str), true);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit(Plan $plan)
|
|
{
|
|
return view('plan/edit_form', ['plan' => $plan]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, Plan $plan)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(Plan $plan)
|
|
{
|
|
//
|
|
}
|
|
}
|