| Server IP : 103.161.17.216 / Your IP : 216.73.216.1 Web Server : nginx/1.18.0 System : Linux tipsysaigoncharming 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 7.4.3-4ubuntu2.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/tipsysaigon.vn/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use Auth;
use Session;
use App\Models\Slider;
use App\Models\Attr;
use App\Http\Requests;
use Illuminate\Support\Facades\Redirect;
use App\Models\Post;
use App\Models\Category;
use App\Models\Cate;
use App\Models\CatePost;
session_start();
class PostController extends Controller
{
public function AuthLogin() {
$admin_id=session::get('admin_id');
if($admin_id){
return Redirect::to('dashboard');
}
else{
return Redirect::to('admin')->send();
}
}
public function add_post(){
$this->AuthLogin();
$cate_post = CatePost::orderBy('cate_post_id','DESC')->get();
return view('admin.post.add_post')->with(compact('cate_post'));
}
public function save_post(Request $request){
$this->AuthLogin();
$data = $request->all();
$post = new Post();
$post->post_title = $data['post_title'];
$post->post_slug = $data['post_slug'];
$post->post_desc = $data['post_desc'];
$post->post_content = $data['post_content'];
$post->post_meta_desc = $data['post_meta_desc'];
$post->post_meta_keywords = $data['post_meta_keywords'];
$post->cate_post_id = $data['cate_post_id'];
$post->post_status = $data['post_status'];
$get_image = $request->file('post_image');
if($get_image){
$get_name_image = $get_image->getClientOriginalName(); //lay ten của hình ảnh
$name_image = current(explode('.',$get_name_image));
$new_image = $name_image.rand(0,99).'.'.$get_image->getClientOriginalExtension();
$get_image->move('public/uploads/post',$new_image);
$post->post_image = $new_image;
$post->save();
Session::put('message','Thêm bài viết thành công');
return redirect()->back();
}else{
Session::put('message','Làm ơn thêm hình ảnh');
return redirect()->back();
}
}
public function all_post(){
$this->AuthLogin();
$all_post = Post::with('cate_post')->orderBy('cate_post_id')->get();
return view('admin.post.list_post')->with(compact('all_post',$all_post));
}
public function delete_post($post_id){
$this->AuthLogin();
$post = Post::find($post_id);
$post_image = $post->post_image;
if($post_image){
$path ='public/uploads/post/'.$post_image;
unlink($path);
}
$post->delete();
Session::put('message','Xóa bài viết thành công');
return redirect()->back();
}
public function edit_post($post_id){
$cate_post = CatePost::orderBy('cate_post_id')->get();
$post = Post::find($post_id);
return view('admin.post.edit_post')->with(compact('post','cate_post'));
}
public function update_post(Request $request,$post_id){
$this->AuthLogin();
$data = $request->all();
$post = Post::find($post_id);
$post->post_title = $data['post_title'];
$post->post_slug = $data['post_slug'];
$post->post_desc = $data['post_desc'];
$post->post_content = $data['post_content'];
$post->post_meta_desc = $data['post_meta_desc'];
$post->post_meta_keywords = $data['post_meta_keywords'];
$post->cate_post_id = $data['cate_post_id'];
$post->post_status = $data['post_status'];
$get_image = $request->file('post_image');
if($get_image){
//xoa anh cu
$post_image_old = $post->post_image;
$path ='public/uploads/post/'.$post_image_old;
unlink($path);
//cap nhat anh moi
$get_name_image = $get_image->getClientOriginalName(); //lay ten của hình ảnh
$name_image = current(explode('.',$get_name_image));
$new_image = $name_image.rand(0,99).'.'.$get_image->getClientOriginalExtension();
$get_image->move('public/uploads/post',$new_image);
$post->post_image = $new_image;
}
$post->save();
Session::put('message','Cập nhật bài viết thành công');
return redirect()->back();
}
public function danh_muc_bai_viet(Request $request,$post_slug){
//category post
$category_post = CatePost::orderBy('cate_post_id','DESC')->get();
//slide
$slide =Slider::orderby('slider_id','desc')->get();
$cate=Cate::orderby('cate_id','ASC')->get();
$cate_product=Category::where('category_status','1')->orderby('category_id','desc')->with('cate')->get();
$brand_product = DB::table('tbl_brand')->where('brand_status','0')->orderby('brand_id','desc')->get();
$all_product=DB::table('tbl_product')->where('product_status','1')->orderby('product_id','desc')->get();
$all_attr =Attr::orderby('attr_id','asc')->with('product')->get();
$catepost = CatePost::where('cate_post_slug',$post_slug)->take(1)->get();
foreach($catepost as $key => $cate){
//seo
$meta_desc = $cate->cate_post_desc;
$meta_keywords = $cate->cate_post_slug;
$meta_title = $cate->cate_post_name;
$cate_id = $cate->cate_post_id;
$url_canonical = $request->url();
$share_image = url('public/frontend/images/share_news.png');
//--seo
}
$post_cate = Post::with('cate_post')->where('post_status',0)->where('cate_post_id',$cate_id)->paginate(5);
$category_name = DB::table('tbl_category_post')->where('tbl_category_post.cate_post_slug',$post_slug)->limit(1)->get();
// return view('pages.baiviet.danhmucbaiviet')->with('category',$cate_product)->with('brand',$brand_product)->with('meta_desc',$meta_desc)->with('meta_keywords',$meta_keywords)->with('meta_title',$meta_title)->with('url_canonical',$url_canonical)->with('slider',$slider)->with('post_cate',$post_cate)->with('category_post',$category_post)->with('share_image',$share_image)->with('cate',$cate);
return view('pages.baiviet.danhmucbaiviet')->with(compact('cate_product','brand_product','meta_keywords','meta_desc','meta_title','url_canonical','all_product','all_attr','cate','slide','category_post','post_cate','share_image','category_name'));
}
public function bai_viet(Request $request,$post_slug){
//category post
$category_post = CatePost::orderBy('cate_post_id','DESC')->get();
//slide
$slide =Slider::orderby('slider_id','desc')->get();
$cate=Cate::orderby('cate_id','ASC')->get();
$cate_product=Category::where('category_status','1')->orderby('category_id','desc')->with('cate')->get();
$brand_product = DB::table('tbl_brand')->where('brand_status','0')->orderby('brand_id','desc')->get();
$all_product=DB::table('tbl_product')->where('product_status','1')->orderby('product_id','desc')->get();
$all_attr =Attr::orderby('attr_id','asc')->with('product')->get();
$post_by_id = Post::with('cate_post')->where('post_status',0)->where('post_slug',$post_slug)->take(1)->get();
foreach($post_by_id as $key => $p){
//seo
$meta_desc = $p->post_meta_desc;
$meta_keywords = $p->post_meta_keywords;
$meta_title = $p->post_title;
$cate_id = $p->cate_post_id;
$url_canonical = $request->url();
$cate_post_id = $p->cate_post_id;
$post_id = $p->post_id;
$share_image = url('public/uploads/post/'.$p->post_image);
//--seo
}
//update views
$post = Post::where('post_id',$post_id)->first();
$post->post_views = $post->post_views + 1;
$post->save();
//related post
$related = Post::with('cate_post')->where('post_status',0)->where('cate_post_id',$cate_post_id)->whereNotIn('post_slug',[$post_slug])->take(5)->get();
// return view('pages.baiviet.baiviet')->with('category',$cate_product)->with('brand',$brand_product)->with('meta_desc',$meta_desc)->with('meta_keywords',$meta_keywords)->with('meta_title',$meta_title)->with('url_canonical',$url_canonical)->with('slider',$slider)->with('post_by_id',$post_by_id)->with('category_post',$category_post)->with('related',$related)->with('share_image',$share_image);
return view('pages.baiviet.baiviet')->with(compact('cate_product','brand_product','meta_keywords','meta_desc','meta_title','url_canonical','all_product','all_attr','cate','slide','category_post','post_by_id','share_image','related'));
}
}