Revize b323292b
Přidáno uživatelem Marek Lovčí před téměř 5 roky(ů)
app/Http/Controllers/ArtefactController.php | ||
---|---|---|
3 | 3 |
namespace App\Http\Controllers; |
4 | 4 |
|
5 | 5 |
use App\Artefact; |
6 |
use App\ArtefactCategory; |
|
7 |
use App\Category; |
|
6 | 8 |
use Illuminate\Http\Request; |
7 | 9 |
use Illuminate\Support\Facades\DB; |
8 | 10 |
|
... | ... | |
25 | 27 |
return view('artefact.default', ['artefacts' => $artefacts]); |
26 | 28 |
} |
27 | 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 |
|
|
28 | 54 |
/** |
29 | 55 |
* Returns view of single artefact given by its id. |
30 | 56 |
* |
... | ... | |
34 | 60 |
public function view($id) |
35 | 61 |
{ |
36 | 62 |
$artefact = Artefact::find($id); |
63 |
$artefact['likes'] = Artefact::find($id)->users()->count(); |
|
37 | 64 |
|
38 | 65 |
return view('artefact.view', ['artefact' => $artefact]); |
39 | 66 |
} |
Také k dispozici: Unified diff
Merge branch 'develop'