?
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB ;
use Storage;
use App\Models\Widget;
use Intervention\Image\Facades\Image;
class WidgetController extends Controller
{
public static function GetTheWidgetValue($id){
$WidgetData = Widget::find($id);
return $WidgetData ;
}
public static function ShowData ($type) {
$Widgetdata = Widget::Where('type', $type)
->Where('currentstatus',0)
->get();
return $Widgetdata ;
}
public static function ShowDataSlider ($type) {
$Widgetdata = Widget::Where('type', $type)
->orderBy('key', 'ASC')
->get();
return $Widgetdata ;
}
function showDatalist(){
$dataviewer = Widget::WHERE('currentstatus','0')
->Where('visibileType','2')
->orderBy('orderby', 'DESC')
->paginate(20);
return view('widget.widgetmanager',['data'=>$dataviewer]);
}
function UpdateWidget(Request $req,$slug){
if($slug == '' ){
$slug = 1 ;
}
$WidgetUpdate = Widget::find($slug) ;
// print_R($req->input());
if (count($req->all()) > 0){
$WidgetUpdate->title = $req->title ;
$WidgetUpdate->subtitle = $req->subtitle ;
$WidgetUpdate->url = $req->url ;
$WidgetUpdate->key = $req->key ;
$WidgetUpdate->secret = $req->secret ;
$WidgetUpdate->password = $req->password ;
$WidgetUpdate->note = $req->note ;
$WidgetUpdate->ctatitle = $req->ctatitle ;
$WidgetUpdate->ctaurl = $req->ctaurl ;
$WidgetUpdate->isDirty('title');
$WidgetUpdate->isDirty('subtitle');
$WidgetUpdate->isDirty('url');
$WidgetUpdate->isDirty('key');
$WidgetUpdate->isDirty('secret');
$WidgetUpdate->isDirty('password');
$WidgetUpdate->isDirty('note');
$WidgetUpdate->isDirty('ctatitle');
$WidgetUpdate->isDirty('ctaurl');
$WidgetUpdate->save();
if($req->hasfile('uploadImage'))
{
$indexcount = 1 ;
//single image upload
foreach($req->file('uploadImage') as $file)
{
$getExt = $file->extension();
$random = substr(md5(mt_rand()), 0, 5);
$fileName = 'wig24'.$WidgetUpdate->id.'_'.$random.'.'.$getExt ;
$path = $file->storeAs('public/cmsassets', $fileName );
$path = $file->storeAs('public/cmsassets/thumb', $fileName );
// storage/cmsassets/thumb/
// $thumbnailpath = $file->storeAs('public/thumbnails/', $fileName );
// "E:\00xamp\htdocs\3Samaj\public\storage/cmsassets/thumbwig2417_c7ac6.jpg"
$thumbnailpath = public_path('storage/cmsassets/thumb/'.$fileName);
echo '<br><br><br><br><br><br><br>'.$fileName.'<br>'.$thumbnailpath;
// Thumbnail
$width = 876;
$height= 445;
$img = Image::make($thumbnailpath)->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
$img->save($thumbnailpath);
$WidgetImage = Widget::where('id',$WidgetUpdate->id)->update(['image'=> $fileName]);
$indexcount++ ;
}
}
return redirect('widget/'.$slug)->with('sucess', 'updated sucessfully');
}
return view('widget.updatewidget',['data'=>$WidgetUpdate]);
}
}