Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

familytree365/backend

90 stars
3 code files
View familytree365/backend on GitHub

app/Helpers/helpers.php

Open in GitHub
if (! 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 GitHub
use 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
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.