67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Str;
|
|
|
|
// Template
|
|
// if (! function_exists('my_custom_function')) {
|
|
// function my_custom_function($param) {
|
|
// }
|
|
// }
|
|
|
|
if (! function_exists('store_file')) {
|
|
function store_file($file, $path, $disk = 'public')
|
|
{
|
|
if (isset($file)) {
|
|
$randomFilename = Str::random(35).time().'.'.$file->getClientOriginalExtension();
|
|
$originalFileName = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)).'.'.$file->getClientOriginalExtension();
|
|
|
|
$file->storeAs($path, $randomFilename, $disk);
|
|
|
|
return [
|
|
'randomFileName' => $randomFilename,
|
|
'originalFileName' => $originalFileName,
|
|
'isSuccess' => true,
|
|
];
|
|
} else {
|
|
return [
|
|
'randomFileName' => null,
|
|
'originalFileName' => null,
|
|
'isSuccess' => false,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_role_name')) {
|
|
function get_role_name($role = null) {
|
|
|
|
if($role === null){
|
|
$role = Auth::user()->role_id;
|
|
}
|
|
|
|
switch($role) {
|
|
case '1':
|
|
return "Administrator";
|
|
case '2':
|
|
return "Admin Monitoring";
|
|
case '3':
|
|
return "Perusahaan";
|
|
case '4':
|
|
return "Admin Konten";
|
|
default:
|
|
return "Role Tidak Dikenal";
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!function_exists('shorten_text')) {
|
|
function shorten_text($text, $maxLength = 100) {
|
|
if (strlen($text) > $maxLength) {
|
|
return substr($text, 0, $maxLength) . '...';
|
|
}
|
|
|
|
return $text;
|
|
}
|
|
}
|