ProjectImageController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 15 2
A store() 0 10 1
1
<?php
2
3
namespace Larafolio\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Larafolio\Models\Project;
7
use Intervention\Image\Facades\Image as Intervention;
8
use Illuminate\Support\Facades\Storage;
9
10
class ProjectImageController extends Controller
11
{
12
    /**
13
     * Show images for project.
14
     *
15
     * @param \Illuminate\Http\Request $request Request from user.
16
     * @param Larafolio\Models\Project $project Project to show.
17
     *
18
     * @return \Illuminate\Http\Response
19
     */
20
    public function index(Request $request, Project $project)
21
    {
22
        if ($request->ajax()) {
23
            $images = $project->imagesWithProps();
24
25
            return response()->json($images);
26
        }
27
28
        $images = $project->imagesWithProps();
29
30
        return view('larafolio::images.manage', [
31
            'project' => $project,
32
            'images'  => $images,
33
        ]);
34
    }
35
36
    /**
37
     * Add a new project to the portfolio.
38
     *
39
     * @param \Illuminate\Http\Request $request Form request.
40
     * @param Larafolio\Models\Project $project The project to add the image too.
41
     */
42
    public function store(Request $request, Project $project)
43
    {
44
        $imagePath = $request->file('file')->store('public/images');
45
46
        $image = Intervention::make(Storage::get($imagePath))->encode('jpg', 50);
47
48
        Storage::put($imagePath, $image);
49
50
        $this->user->addImageToProject($project, ['path' => $imagePath]);
51
    }
52
}
53