1 |
74e290c2
|
Adam Mištera
|
<?php
|
2 |
|
|
|
3 |
|
|
namespace App\Http\Controllers;
|
4 |
|
|
|
5 |
|
|
use App\Artefact;
|
6 |
fb354d59
|
rizir01
|
use App\ArtefactCategory;
|
7 |
|
|
use App\Category;
|
8 |
74e290c2
|
Adam Mištera
|
use Illuminate\Http\Request;
|
9 |
|
|
use Illuminate\Support\Facades\DB;
|
10 |
|
|
|
11 |
|
|
class ArtefactController extends Controller
|
12 |
|
|
{
|
13 |
21570473
|
Adam Mištera
|
public function __construct()
|
14 |
|
|
{
|
15 |
|
|
$this->middleware('auth');
|
16 |
|
|
}
|
17 |
|
|
|
18 |
10222730
|
Adam Mištera
|
/**
|
19 |
|
|
* Returns view of all artefacts.
|
20 |
|
|
*
|
21 |
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
22 |
|
|
*/
|
23 |
74e290c2
|
Adam Mištera
|
public function default()
|
24 |
|
|
{
|
25 |
10222730
|
Adam Mištera
|
$artefacts = Artefact::all();
|
26 |
74e290c2
|
Adam Mištera
|
|
27 |
|
|
return view('artefact.default', ['artefacts' => $artefacts]);
|
28 |
|
|
}
|
29 |
10222730
|
Adam Mištera
|
|
30 |
fb354d59
|
rizir01
|
/**
|
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 |
10222730
|
Adam Mištera
|
/**
|
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 |
|
|
|
64 |
|
|
return view('artefact.view', ['artefact' => $artefact]);
|
65 |
|
|
}
|
66 |
74e290c2
|
Adam Mištera
|
}
|