-
app/Helpers/helpers.php
Open in GitHubif (! function_exists('unique_random')) { function unique_random($table, $col, $chars = 16) { $unique = false; $tested = []; do { $random = Str::random($chars); if (in_array($random, $tested)) { continue; } $count = DB::table($table)->where($col, '=', $random)->count(); $tested[] = $random; if ($count == 0) { $unique = true; } } while (! $unique); return $random; } }
-
app/Http/Controllers/DnaController.php
Open in GitHubuse App\Models\Dna; use Auth; use Illuminate\Http\Request; class DnaController extends Controller { public function store(Request $request) { $currentUser = Auth::user(); $file_name = 'dna_'.$request->file('file')->getClientOriginalName().uniqid().'.'.$request->file('file')->extension(); $request->file->storeAs('dna', $file_name); define('STDIN', fopen('php://stdin', 'r')); $random_string = unique_random('dnas', 'variable_name', 5); $var_name = 'var_'.$random_string; $filename = 'app/dna/'.$file_name; $user_id = $currentUser->id; } }
-
composer.json
Open in GitHub{ "name": "familytree365/backend", "require": { "php": "^7.4|^8.0", "algolia/algoliasearch-client-php": "^3.0", "algolia/scout-extended": "^1.18", // ... }, "autoload": { "files": [ "app/Helpers/helpers.php" ], }, // ... other settings }