1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- class HelperController extends Controller
- {
- public function upload_single_photo ($photo, $type)
- {
- $rand = rand(0,999);
- $name = time().$rand.'.'.$type;
- // file_put_contents(public_path().'/uploads/'.$name, file_get_contents($photo));
- return $link = 'uploads/'.$name;
- }
- public function csvToArray ($filename = '', $delimiter = ',')
- {
- if (!file_exists($filename) || !is_readable($filename))
- return false;
- $header = null;
- $data = array();
- if (($handle = fopen($filename, 'r')) !== false)
- {
- while (($row = fgetcsv($handle, 1000, $delimiter)) !== false)
- {
- if (!$header)
- $header = $row;
- else
- $data[] = array_combine($header, $row);
- }
- fclose($handle);
- }
- return ['users' => $data] ;
- }
- public function display_duplicated_emails ($emails)
- {
- $duplicates = array_diff_key($emails, array_unique($emails));
- if(!empty($duplicates)){
- $error = [];
- foreach ($duplicates as $key => $duplicate) {
- $error[] = $duplicate ." has already duplicate in json";
- }
- return response()->json(compact('error'),400);
- }
- }
- } //class
|