download file from view page
i have column in the resource that enable users to download the uploaded files from it, i want also to enable users to download it from the view page
here is my code in the model :
protected $casts = ['file'=> 'array'];
public function getFileAttribute($value)
{
if (empty($value) || is_null($value)) {
return "No file";
}
$file = explode(',', $value);
$url = rtrim(env('APP_URL'), '/'); // Get the URL from the .env file and remove trailing slash
$forReturn = [];
foreach ($file as $val) {
$val = trim($val, '[]"');
$val = ltrim($val, '/');
if (!empty($val)) {
array_push($forReturn, "<a href='{$url}/storage/{$val}'>Download</a>");
}
}
if (empty($forReturn)) {
return "No file";
}
return $forReturn;
}
and this from the form resource :
FileUpload::make('file')
->acceptedFileTypes(['image/*','application/pdf','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'])
->directory('tickets')->multiple(),
this from the table:
Tables\Columns\TextColumn::make('file')->html(function ($record) {
if (isset($record->file['tickets'])) {
return html("{$record->file['tickets']}");
} else {
return null;
}
}, true)->openUrlInNewTab(),
here is my code in the model :
protected $casts = ['file'=> 'array'];
public function getFileAttribute($value)
{
if (empty($value) || is_null($value)) {
return "No file";
}
$file = explode(',', $value);
$url = rtrim(env('APP_URL'), '/'); // Get the URL from the .env file and remove trailing slash
$forReturn = [];
foreach ($file as $val) {
$val = trim($val, '[]"');
$val = ltrim($val, '/');
if (!empty($val)) {
array_push($forReturn, "<a href='{$url}/storage/{$val}'>Download</a>");
}
}
if (empty($forReturn)) {
return "No file";
}
return $forReturn;
}
and this from the form resource :
FileUpload::make('file')
->acceptedFileTypes(['image/*','application/pdf','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'])
->directory('tickets')->multiple(),
this from the table:
Tables\Columns\TextColumn::make('file')->html(function ($record) {
if (isset($record->file['tickets'])) {
return html("{$record->file['tickets']}");
} else {
return null;
}
}, true)->openUrlInNewTab(),
