Skip to content

Instantly share code, notes, and snippets.

@sleeping-owl
Created May 21, 2015 13:22
Show Gist options
  • Save sleeping-owl/a724d3ca3c6cdfeeac9a to your computer and use it in GitHub Desktop.
Save sleeping-owl/a724d3ca3c6cdfeeac9a to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Database\Eloquent\ModelNotFoundException;
class MonumentsController extends Controller
{
public function getIndex()
{
$article = Article::whereUrl('system/monuments')->first();
if (!$article)
{
$article = new Article;
$article->title = 'Памятники';
}
return View::make('monuments.index', compact('article'));
}
public function getCategory($categoryUrl)
{
$category = MonumentCategory::whereUrl($categoryUrl)->first();
if (!$category) App::abort(404);
$monuments = $category->monuments()->with('district')->get();
return View::make('monuments.category', compact('category', 'monuments'));
}
public function getDistrict($districtUrl)
{
$district = District::whereUrl($districtUrl)->first();
if (!$district) App::abort(404);
$monuments = $district->monuments()->with('district')->get();
return View::make('monuments.category', compact('monuments'))->withCategory($district);
}
public function getFull($monumentId)
{
try
{
$monument = Monument::findOrFail($monumentId);
} catch (ModelNotFoundException $e)
{
App::abort(404);
}
return View::make('monuments.full', compact('monument'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment