Completed
Push — master ( 3d4150...00d7a1 )
by Nicolas
03:57
created

RecipeController::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php namespace Modules\Recipe\Http\Controllers\Admin;
2
3
use Laracasts\Flash\Flash;
4
use Illuminate\Http\Request;
5
use Modules\Media\Repositories\FileRepository;
6
use Modules\Recipe\Entities\Recipe;
7
use Modules\Recipe\Repositories\RecipeRepository;
8
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
9
10
class RecipeController extends AdminBaseController
11
{
12
    /**
13
     * @var RecipeRepository
14
     */
15
    private $recipe;
16
    /**
17
     * @var FileRepository
18
     */
19
    private $file;
20
21
    public function __construct(RecipeRepository $recipe, FileRepository $file)
22
    {
23
        parent::__construct();
24
25
        $this->recipe = $recipe;
26
        $this->file = $file;
27
    }
28
29
    /**
30
     * Display a listing of the resource.
31
     *
32
     * @return Response
33
     */
34
    public function index()
35
    {
36
        $recipes = $this->recipe->all();
37
38
        return view('recipe::admin.recipes.index', compact('recipes'));
39
    }
40
41
    /**
42
     * Show the form for creating a new resource.
43
     *
44
     * @return Response
45
     */
46
    public function create()
47
    {
48
        return view('recipe::admin.recipes.create');
49
    }
50
51
    /**
52
     * Store a newly created resource in storage.
53
     *
54
     * @param  Request $request
55
     * @return Response
56
     */
57
    public function store(Request $request)
58
    {
59
        $this->recipe->create($request->all());
60
61
        flash()->success(trans('core::core.messages.resource created', ['name' => trans('recipe::recipes.title.recipes')]));
62
63
        return redirect()->route('admin.recipe.recipe.index');
64
    }
65
66
    /**
67
     * Show the form for editing the specified resource.
68
     *
69
     * @param  Recipe $recipe
70
     * @return Response
71
     */
72
    public function edit(Recipe $recipe)
73
    {
74
        $galleryFiles = $this->file->findMultipleFilesByZoneForEntity('gallery', $recipe);
75
        $featured_image = $this->file->findFileByZoneForEntity('featured_image', $recipe);
76
77
        return view('recipe::admin.recipes.edit', compact('recipe', 'galleryFiles', 'featured_image'));
78
    }
79
80
    /**
81
     * Update the specified resource in storage.
82
     *
83
     * @param  Recipe $recipe
84
     * @param  Request $request
85
     * @return Response
86
     */
87 View Code Duplication
    public function update(Recipe $recipe, Request $request)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
    {
89
        $this->recipe->update($recipe, $request->all());
90
91
        flash()->success(trans('core::core.messages.resource updated', ['name' => trans('recipe::recipes.title.recipes')]));
92
93
        return redirect()->route('admin.recipe.recipe.index');
94
    }
95
96
    /**
97
     * Remove the specified resource from storage.
98
     *
99
     * @param  Recipe $recipe
100
     * @return Response
101
     */
102 View Code Duplication
    public function destroy(Recipe $recipe)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
    {
104
        $this->recipe->destroy($recipe);
105
106
        flash()->success(trans('core::core.messages.resource deleted', ['name' => trans('recipe::recipes.title.recipes')]));
107
108
        return redirect()->route('admin.recipe.recipe.index');
109
    }
110
}
111