Example #1
0
 public static function getCatgoryFullContentByPageID($cat_id, $page_id)
 {
     $itemsPerPage = 5;
     $contentPerSubject = 3;
     $resultArr = [];
     $subjectObj = Subjects::where('cat_id', $cat_id)->orderBy('last_reply_time', 'desc')->get();
     foreach ($subjectObj as $subject) {
         $contentObj = Contents::where('content_id', $subject->subject_id)->first();
         $userObj = User::find($subject->po_id);
         $cookieObj = ChCookie::where('id', $userObj->cookie_id)->first();
         $shortCookie = $cookieObj->short_cookie;
         $tmpArr = ['subject_id' => $contentObj->content_id, 'subject_text' => $contentObj->content, 'subject_cookie' => $shortCookie, 'subject_create_time' => $subject->created_at, 'subject_img' => $contentObj->image, 'contents' => []];
         $contentObj = Contents::where('subject_id', $subject->subject_id)->where('content_id', '!=', $subject->subject_id)->orderBy('content_id', 'desc')->get();
         foreach ($contentObj as $content) {
             $userObj = User::find($content->po_id);
             $cookieObj = ChCookie::where('id', $userObj->id)->first();
             $shortCookie = $cookieObj->short_cookie;
             $tmpContent = ['content_id' => $content->content_id, 'content_text' => $content->content, 'content_cookie' => $shortCookie, 'content_create_time' => $content->created_at, 'content_img' => $content->image];
             array_push($tmpArr['contents'], $tmpContent);
         }
         array_push($resultArr, $tmpArr);
     }
     //var_dump($resultArr);
     return $resultArr;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // $this->call(UserTableSeeder::class);
     Model::reguard();
     User::create(['email' => '*****@*****.**', 'password' => bcrypt('kantavee'), 'name' => '*****@*****.**']);
     Contents::create(['title' => 'content migrate', 'description' => 'descript migrate', 'status' => 1, 'body' => '<h2>Hello world!</h2>']);
 }
 public function update(Request $request)
 {
     $body = $this->bodyReplace($request->input('body'));
     $content = Contents::find($request->input('id'));
     if ($content == null) {
         return Response::json(array('result' => false, 'message' => 'can not defind this content'));
     }
     $content->title = $request->input('title');
     $content->description = $request->input('description');
     $content->body = $body;
     $content->thumbnail = $request->input('thumbnail');
     $content->start = $request->input('start');
     $content->updated_at = Carbon::now('Asia/Bangkok');
     $content->end = $request->input('end');
     $content->status = $request->input('status');
     $result = $content->save();
     if ($result) {
         return Response::json(array('result' => true, 'message' => 'Update success.', 'obj' => $result));
     } else {
         return Response::json(array('result' => false, 'message' => 'Update fail.', 'obj' => $result));
     }
 }
 public function getContentByCatID(Request $request, $cat_id)
 {
     $page_id = $request->get('p');
     $catObj = Categories::find($cat_id);
     $data['cat_name'] = $catObj->cat_name;
     $data['fullContent'] = Contents::getCatgoryFullContentByPageID($cat_id, 1);
     return View::make('catview', $data);
 }
 public function news($id)
 {
     if ($id == null) {
         return redirect()->intended('/');
     }
     $news = Contents::where('id', $id)->get()->first();
     $view = \View::make('home.news');
     $news->body = str_replace(Config::get('image.name'), Config::get('image.host'), $news->body);
     $view->with('news', $news);
     return $view;
 }