public function index() { if (!isset($_GET['page'])) { $_GET['page'] = 1; } $contents = Cache::remember('contents-' . $_GET['page'], 60, function () { $data = Content::orderBy('id', 'desc')->paginate(5); $data->setPath('/'); return $data; }); return view('Site.main', ['contents' => $contents, 'popular' => \App\Layout::popular()]); }
Route::group(['domain' => 'www.' . config('settings.domain')], function () { Route::get('/', 'Site\\MainController@index'); }); Route::group(['domain' => '{id}.' . config('settings.domain')], function () { Route::get('/', function ($id) { if (Cache::has($id)) { $detail = Cache::get($id); } else { try { $detail = \App\Content::where('seo', $id)->firstOrFail(); Cache::put($id, $detail, 15); } catch (ModelNotFoundException $e) { return redirect('/'); } } return view('Site.detail', ['content' => $detail, 'popular' => \App\Layout::popular()]); }); }); Route::get('/', function () { return redirect('http://www.' . config('settings.domain')); }); /* Route::group(['middleware' => ['web']], function () { Route::get('/', 'Site\MainController@index'); Route::get('{id}', 'Site\MainController@detail');
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $layout = Layout::find($id); $layout->delete(); return \Redirect::route('layout.index'); }
/** * Attach Elements to layout. * * @param \Element ID */ public function attachMessage($elementId, $messageId) { //TODO Error handeling if message is already added $element = Element::find($elementId); $element->messages()->attach($messageId); $data['element'] = Layout::find($elementId); $data['linkedMessages'] = ElementsController::getMessages($elementId); $data['unlinkedMessages'] = ElementsController::getUnlinkedMessages($elementId); //TODO redirect to correct url return redirect()->back(); //return \View::make('Elements.show')->with($data); }