Home > Mobile >  How to fix Error 404 when trying to download PDF file from the public folder
How to fix Error 404 when trying to download PDF file from the public folder

Time:02-20

Have been receiving a 404 error message when trying to download a pdf file that was successfully saved.

Index

<tbody>
    @foreach ($allData as $key => $patient)
    <tr>
        <td>{{ $patient -> card_number }}</td>
        <td>{{ $patient -> patient_type }}</td>
        <td>{{ $patient -> patient_hmo }}</td>
        <td>{{ $patient -> patient_firstname }} {{ $patient -> patient_lastname }}</td>
        {{-- <td>{{ \Carbon\Carbon::parse($patient -> patient_dob)->diff(\Carbon\Carbon::now())->format('%y years, %m months and %d days') }}</td> --}}
        <td>{{\Carbon\Carbon::parse($patient -> patient_dob)->diff(\Carbon\Carbon::now())->format('%y')  }}</td>
        <td>{{ $patient -> patient_phone }}</td>
        <td>{{ $patient -> patient_gender }}</td>
        <td>{{ $patient -> patient_kin_name }}</td>
        <td>{{ $patient -> patient_kin_phone }}</td>
        <td><a href="/file/download/{{ $patient->file }}" target="blank">Download</a></td>
        <td>


            <a  title="View Data" data-toggle="modal" data-target="#modal-center{{ $patient->id }}"> <i ></i></a>

            <a href="{{ route('patient.edit',$patient->id) }}"  title="Edit Data" > <i ></i></a>

            <a href="{{ route('patient.delete',$patient->id) }}"    id="delete" title="Delete Data" > <i ></i></a>
        </td>

    </tr>
    @endforeach

</tbody>

web

Route::get('/file/download/{file}',[PatientController::class,'downloads']);

PatientController

public function downloads($file)
{
return response()->download('upload/pdf'.$file);
}

Database

enter image description here

Error page

enter image description here

CodePudding user response:

This works directly without Route or any controller.


<tbody>
    @foreach ($allData as $key => $patient)
    <tr>
        <td>{{ $patient -> card_number }}</td>
        <td>{{ $patient -> patient_type }}</td>
        <td>{{ $patient -> patient_hmo }}</td>
        <td>{{ $patient -> patient_firstname }} {{ $patient -> patient_lastname }}</td>
        <td>{{\Carbon\Carbon::parse($patient -> patient_dob)->diff(\Carbon\Carbon::now())->format('%y')  }}</td>
        <td>{{ $patient -> patient_phone }}</td>
        <td>{{ $patient -> patient_gender }}</td>
        <td>{{ $patient -> patient_kin_name }}</td>
        <td>{{ $patient -> patient_kin_phone }}</td>

        <td><a href="{{ url('/'.$patient->file) }}">Download</a></td>
        <td>


            <a  title="View Data" data-toggle="modal" data-target="#modal-center{{ $patient->id }}"> <i ></i></a>

            <a href="{{ route('patient.edit',$patient->id) }}"  title="Edit Data" > <i ></i></a>

            <a href="{{ route('patient.delete',$patient->id) }}"    id="delete" title="Delete Data" > <i ></i></a>
        </td>

    </tr>
    @endforeach

</tbody>
  • Related