- Forums
- laravel
- Append To Lavarel Json Api Output
This Page Contains information about Append To Lavarel Json Api Output By dd in category laravel with 0 Replies. [5116], Last Updated: Mon Jun 24, 2024
dd
Mon May 08, 2023
0 Comments
260 Visits
public function show($token) {
$files = UploadResource::collection(Upload::where('token', $token)->get());
//$files[0]->name = 'aquino';
if ($files->count() > 0) {
//dd($files->resource[0]->resource);
//print_r($files->resource[0]->resource);die();
//print_r($files);die();
// create a temporary placeholder for the found files with the token and give it a unituq key with expiration date.
// add days from now
// /https://www.digitalocean.com/community/tutorials/easier-datetime-in-laravel-and-php-with-carbon#manipulating-the-date-and-time
$current = Carbon::now();
$Expires = $current->addDays(5);
// append to lavarel json api output
foreach($files as $i=>$file){
//https://www.codexworld.com/how-to/generate-unique-and-secure-api-keys-with-php/
$secretKey = bin2hex(random_bytes(32));
$files[$i]->secret = $secretKey;
//print_r($file->resource->attributes);
$key = Download::create([
// COLUMN NAMES AND VALUES
'file_id' => 1,
'secret_key' => $secretKey,
'expires' => $Expires,
]);
}