1
|
<?php
|
2
|
|
3
|
namespace App\Http\Controllers;
|
4
|
|
5
|
use App\Artefact;
|
6
|
use App\ArtefactCategory;
|
7
|
use App\Category;
|
8
|
use Illuminate\Http\Request;
|
9
|
use Illuminate\Support\Facades\DB;
|
10
|
|
11
|
class ArtefactController extends Controller
|
12
|
{
|
13
|
public function __construct()
|
14
|
{
|
15
|
$this->middleware('auth');
|
16
|
}
|
17
|
|
18
|
/**
|
19
|
* Returns view of all artefacts.
|
20
|
*
|
21
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
22
|
*/
|
23
|
public function default()
|
24
|
{
|
25
|
$artefacts = Artefact::all();
|
26
|
|
27
|
return view('artefact.default', ['artefacts' => $artefacts]);
|
28
|
}
|
29
|
|
30
|
/**
|
31
|
* Returns view of artefacts related to the chosen category
|
32
|
*
|
33
|
* @param $id id of the category
|
34
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
35
|
*/
|
36
|
public function showCategory($id)
|
37
|
{
|
38
|
$cateogryArtefacts = ArtefactCategory::where('category_id', $id)->get();
|
39
|
if(count($cateogryArtefacts) > 0)
|
40
|
{
|
41
|
$artefacts = array();
|
42
|
foreach($cateogryArtefacts as $ar)
|
43
|
{
|
44
|
array_push($artefacts, Artefact::where('id', $ar->artefact_id)->get());
|
45
|
}
|
46
|
return view('artefact.category', ['artefacts' => $artefacts]);
|
47
|
}
|
48
|
else
|
49
|
{
|
50
|
return view('artefact.category', ['artefacts' => array()]);
|
51
|
}
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* Returns view of single artefact given by its id.
|
56
|
*
|
57
|
* @param $id int id of the artefact
|
58
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
59
|
*/
|
60
|
public function view($id)
|
61
|
{
|
62
|
$artefact = Artefact::find($id);
|
63
|
$artefact['likes'] = Artefact::find($id)->users()->count();
|
64
|
|
65
|
return view('artefact.view', ['artefact' => $artefact]);
|
66
|
}
|
67
|
}
|