%PDF- %PDF-
Direktori : /home/silvzytp/dsr_code/app/Helpers/ |
Current File : /home/silvzytp/dsr_code/app/Helpers/Helper.php |
<?php use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\File; // const variable define('ALERT_SUCCESS','Record has been saved successfully.'); define('ALERT_DELETE','Record has been remove successfully.'); define('ALERT_UPDATE','Record has been updated successfully.'); define('ALERT_WRONG',['status'=>'error','message'=>'Somthing Wrong!']); define('UNAUTHORIZED',['status'=>'error','message'=>'Access denied! you Don’t Have Permission To Access on This Site']); define('__FILE_PATH__','uploads/'); define('SERVER_ERROR','Server Error!'); function routeName(){ if (Auth::user()->role->slug == 'super-admin') { return 'super'; } else { return 'app'; } } /** * File upload storage * * @param $file * @param $folder * @return \Illuminate\Http\Response */ if (!function_exists('file_store')) { function file_store($file,$folder) { if ($file) { $folderName = __FILE_PATH__.$folder; // folder name // if not have a folder create folder !File::exists($folderName) ? File::makeDirectory($folderName, 0777, true, true) : false; $fileExtension = $file->getClientOriginalExtension(); // file extension $fileName = uniqid(time().rand()).'.'.$fileExtension; // new file name $fileName = $folderName.$fileName; $file->move($folderName, $fileName); // upload file storage }else{ $fileName = NULL; } return $fileName; } } /** * File remove or upload storage * * @param $file * @param $folder * @param $oldFile * @return \Illuminate\Http\Response */ if (!function_exists('file_update')) { function file_update($file,$folder,$oldFile) { if ($file) { $folderName = __FILE_PATH__.$folder; // folder name // if not have a folder create folder !File::exists($folderName) ? File::makeDirectory($folderName, 0777, true, true) : false; file_exists($oldFile) ? unlink($oldFile) : false; // old file remove $fileExtension = $file->getClientOriginalExtension(); // file extension $fileName = uniqid(time().rand()).'.'.$fileExtension; // new file name $fileName = $folderName.$fileName; $file->move($folderName, $fileName); // upload file storage }else{ $fileName = $oldFile; } return $fileName; } } /** * File remove or upload storage * * @param $file * @param $folder * @param $oldFile * @return \Illuminate\Http\Response */ if (!function_exists('file_remove')) { function file_remove($oldFile){ return file_exists($oldFile) ? unlink($oldFile) : false; // file remove } } /** * Date format * * @param $date * @param $format * @return Response; */ if(!function_exists('date_formats')){ function date_formats($date,$format){ return date($format,strtotime($date)); } } /** * Page title * * @param $title * @return Response; */ if(!function_exists('page_title')){ function page_title($siteTitle = null){ return view()->share(['siteTitle'=>$siteTitle]); } } /** * Tooltrip back * * @param $title * @return Response; */ if(!function_exists('tooltip')){ function tooltip($title){ return 'data-container="body" data-toggle="tooltip" data-placement="top" title="" data-original-title="'.$title.'"'; } } /** * Tooltrip white * * @param $title * @return Response; */ if(!function_exists('tooltip_white')){ function tooltip_white($title){ return 'data-container="body" data-toggle="popover" data-trigger="hover" data-placement="top" data-content="'.$title.'" data-original-title="" title=""'; } } /** * Flash message response data * * @param $status * @param $message * @return Response; */ function response_alert($status,$message): array { return ['status'=>$status,'message'=>$message]; } /** * unique id generated * * @param $offset * @param $length * @return \Illuminate\Http\Response */ function unique_data_generate($offset,$length){ // unique order id generate $chars = '0123456789ABCDEFGHIJKLMNOPQRST'; return substr(str_shuffle($chars), $offset, $length); }