/** * store a resource * @param Request $request http request * @param mixed $id id of the resource for updating * @return jsend jsend with newly stored source */ function store(Request $request, $id = null) { //////////////// // Load Data // //////////////// if ($id) { $data = Model::find($id); if (!$data) { return app()->abort(404); } } else { $data = new Model(); } /////////////////////////////////// // Assign posted data to Data // /////////////////////////////////// $data->fill($request->input()); /////////////////////////////////////////////////////////////////// // Validate data // /////////////////////////////////////////////////////////////////// if (!$data->is_valid) { return response()->json(JSend::fail($data->getErrors())->asArray()); } /////////// // Store // /////////// if ($data->save()) { return response()->json(JSend::success(['data' => $data])->asArray()); } else { return response()->json(JSend::fail($data->getErrors())->asArray()); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { try { $inputs = array('des_name', 'des_coors', 'des_instruction', 'related_photos'); $obj = array('message' => 'succeeded'); foreach ($inputs as $field) { $obj[$field] = $request->input($field, ''); } // TODO: cuối cùng vẫn phải chạy Raw SQL -_- $destination = DB::table('Destination')->insertGetId(array('des_name' => $obj['des_name'], 'des_instruction' => $obj['des_instruction'], 'coordinate' => DB::raw("GeomFromText(\"POINT(" . $obj['des_coors']['latitude'] . " " . $obj['des_coors']['longitude'] . ")\")"))); // upload selected images too $images_uploaded = array(); $relPhotos = $obj['related_photos']; if ($relPhotos) { foreach ($relPhotos as $photo) { if ($photo['selected']) { $rq = Request::create("/admin/destination/{$destination}/photo", "POST", [], [], [], [], array('photo_url' => $photo['url'], 'photo_like' => rand(0, 100))); array_push($images_uploaded, Route::dispatch($rq)->getContent()); } } } return response()->json(array('addedObject' => Destination::find($destination), 'addedPhotos' => $images_uploaded)); } catch (\Exception $e) { return response()->json($e); } }
/** * Handle the event. * * @param TravelsWasUpdated $event * @return void */ public function handle(TravelsWasUpdated $event) { $travels = $event->travels; $destinationId = $travels['destination_id']; $endDate = $travels['end_date']; //游记结束时间 $lastDate = Destination::where('id', $destinationId)->value('latest'); if (strtotime($endDate) - strtotime($lastDate) >= 0) { Destination::where('id', $destinationId)->update(['latest' => date('Y-m-d H:i:s', strtotime($endDate))]); } }
/** * 生成sitemap地图 * @return \Illuminate\Http\Response */ public function sitemap() { $data = Cache::remember('sitemap', 30, function () { return ['travels' => Travel::all(), 'destinations' => Destination::all()]; }); $travels = $data['travels']; $destinations = $data['destinations']; $data = compact('travels', 'destinations'); $sitemap = view('index.sitemap', $data); return Response($sitemap, '200')->header('Content-Type', 'text/xml'); }
/** * Display a listing of the resource. * * @return Response */ public function getList($criteria = Null) { //dd("A"); $destinations = Destination::whereIn('status', [0, 1])->orderBy('name', 'asc')->paginate($this->show_per_page); //echo "<pre>"; //print_r($destinations->toArray()); //echo "</pre>"; //exit; // return view('admin.destination.list', ['destinations' => $destinations]); }
/** * [landscape description] * @param [type] $id [description] * @return [type] [description] */ public function landscape($id) { $tours = Tour::getTourByLandScape($id); foreach ($tours as $key => $value) { $tours[$key]->periodNature = HomeController::periodNature($value->period); } $destinationsData = Destination::all(); $departuresData = Departure::all(); $landScapeAbroad = Tour::getLandScapeAbroad(); $landScapeNotAbroad = Tour::getLandScapeNotAbroad(); return view('home.searchtour', compact('tours', 'destinationsData', 'departuresData', 'landScapeAbroad', 'landScapeNotAbroad')); }
/** * @param Request $request * @return Response */ public function getAll(Request $request) { $top = $request->input('top', 4); $withAvatar = (bool) $request->input('withAvatar', FALSE); $data = Destination::all()->take($top); if ($withAvatar == TRUE) { foreach ($data as &$dest) { $dest['avatar'] = $dest->avatar; } } return $data; }
/** * [tour description] * @return [type] [description] */ public function tour() { $featuretours = Tour::getFeatureTour(); foreach ($featuretours as $key => $value) { $featuretours[$key]->periodNature = HomeController::periodNature($value->period); } $newtours = Tour::getNewTour(); foreach ($newtours as $key => $value) { $newtours[$key]->periodNature = HomeController::periodNature($value->period); } $destinations = Destination::all(); $departures = Departure::all(); return view('home.tour', compact('featuretours', 'newtours', 'destinations', 'departures')); }
/** * store a resource * @param Request $request http request * @param mixed $id id of the resource for updating * @return jsend jsend with newly stored source */ function store(Request $request, $id = null) { //////////////// // Load Data // //////////////// if ($id) { $data = Model::find($id); if (!$data) { return app()->abort(404); } } else { $data = new Model(); } /////////////////////////////////// // Assign posted data to Data // /////////////////////////////////// $data->fill($request->input()); /////////////////////////////////////////////////////////////////// // Validate data // /////////////////////////////////////////////////////////////////// # Validate Destinations $destination_id = null; if ($request->input('destination_id') && is_string($request->input('destination_id'))) { $destination = Destination::find($request->input('destination_id')); if ($destination) { $destination_id = $request->input('destination_id'); } else { return response()->json(JSend::fail('InvalidDestination : Destination not found')->asArray()); } } elseif (!is_string($request->input('destination_id'))) { return response()->json(JSend::fail('InvalidDestination : Invalid Destination format')->asArray()); } else { return response()->json(JSend::fail('InvalidDestination : Destination is required')->asArray()); } /////////////////////////// // Embeds Other Document // /////////////////////////// $data->images = $request->input('images'); $data->tags = is_array($request->input('tags')) ? $request->input('tags') : [$request->input('tags')]; $data->destination_id = $destination_id; /////////// // Store // /////////// if ($data->save()) { return response()->json(JSend::success(['data' => $data])->asArray()); } else { return response()->json(JSend::fail($data->getErrors())->asArray()); } }
/** * 游记详情 * @param $slug string * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function travelDetail($slug) { $data = Cache::remember("travel.detail.{$slug}", self::CACHE_TIME, function () use($slug) { $destinationList = $this->destination->getList(12); $detail = $this->travel->where('slug', $slug)->firstOrFail(); $detail->content = Markdown::convertToHtml($detail->content); $destinationInfo = $detail->destination; $travelList = $this->travel->where('destination_id', $destinationInfo['id'])->where('id', '<>', $detail->id)->latest('begin_date')->take(5)->get(); //10篇同目的地的最新游记 $travelList = !$travelList->isEmpty() ? $travelList : ''; return ['destinationList' => $destinationList, 'destinationInfo' => $destinationInfo, 'detail' => $detail, 'travelList' => $travelList]; }); $destinationList = $data['destinationList']; $destinationInfo = $data['destinationInfo']; $detail = $data['detail']; $travelList = $data['travelList']; $seoSuffix = "_{$destinationInfo->destination}游记_tanteng.me"; return view('travel.detail', compact('detail', 'destinationList', 'destinationInfo', 'travelList', 'seoSuffix')); }
/** * @param Request $request * @return Article */ public function doPost(Request $request) { // TODO: Implement doPost() method. /** @var \App\Models\ContentBase $newContent */ $newContent = ContentBase::create(['content_type' => 0]); $newArticle = $newContent->article()->create($request->only($this->articleFields)); if ($request->input('cover_id') != 0) { $newArticle['cover_id'] = $request->input('cover_id'); $newArticle->save(); } // get all checked-in destinations /** @var array $dest */ $dest = array_map(function ($item) { $rs = Destination::where('des_name', $item->des_name)->first(); return $rs; }, (array) json_decode($request->input('destinations'))); foreach ($dest as $d) { /** @var Destination $d */ $m = new ArticleDestination(); $m->article_id = $newArticle->article_id; $m->des_id = $d->des_id; $m->save(); } // get all tagged tags $tags = array_map(function ($item) { return Tag::where('tag_name', $item->tag_name)->first(); }, (array) json_decode($request->input('tagnames'))); /** @var Tag $t */ foreach ($tags as $t) { $m = new ArticleTag(); $m->article_id = $newArticle->article_id; $m->tag_id = $t->tag_id; $m->save(); } return $newArticle; }
/* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', function () { // get top articles (3) $articles = \App\Models\Article::renderAll(3); // get top places (6) $destinations = \App\Models\Destination::all()->random(6); // get top ulibiers (4) $users = \App\Ulibier::all(); return View::make('index', ['articles' => $articles, 'dest' => $destinations, 'users' => $users]); }); Route::get('/register', function () { return View::make('pages.register'); }); Route::get('/profile', function () { return View::make('pages.profile'); }); Route::get('/map', function () { return View::make('pages.map'); }); Route::get('/test/email', function () { return View::make('emails.confirmation');
/** * Show the form for editing the specified resource. * * @param Article $article * @return \Illuminate\Http\Response */ public function edit($article) { $tags = Tag::all(); $dest = Destination::all(['des_id', 'des_name', 'coordinate']); return View::make('pages.blogpost', ['model' => $article, 'action' => array('blog.update', $article->article_id), 'method' => 'PUT', 'tags' => $tags->toJson(), 'dest' => $dest->toJson()]); }