forked from eatvio/eatvio-infra
eating plan added
This commit is contained in:
112
app/Http/Controllers/PlanController.php
Normal file
112
app/Http/Controllers/PlanController.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?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.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Plan $plan
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Plan $plan)
|
||||
{
|
||||
$options1 = $this->unserializeOptions($plan->packet1_options);
|
||||
$options2 = $this->unserializeOptions($plan->packet2_options);
|
||||
$options3 = $this->unserializeOptions($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.
|
||||
*
|
||||
* @param \App\Models\Plan $plan
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Plan $plan)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Plan $plan
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Plan $plan)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Plan $plan
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Plan $plan)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user