mehmetanbaki
1 month ago
548
1
Laravel

Exporting/Importing Files

Posted 1 month ago by mehmetanbaki

Hey Laravelers

I have this issues with exporting files


http://127.0.0.1:8000/url('export')

this is the route with error 404 not found


<?php

namespace App\Http\Controllers;

use App\People;
use Illuminate\Http\Request;
use App\Exports\PeopleExport;
use App\Imports\PoepleImport;
use Maatwebsite\Excel\Facades\Excel;

class PeopleController extends Controller
{
    public function importExportView()
    {
       $people = People::get();
       return view('people', compact('people'));
    }

    public function export()
    {
        return Excel::download(new PeopleExport, 'people.xlsx');
    }

    public function import(Request $request)
    {
        $request->validate([
            'import_file' => 'required'
        ]);
        Excel::import(new PeopleImport,request()->file('import_file'));

        return redirect()->back();
    }
}

this is the controller


Route::get('/people', '[email protected]');
Route::post('/people/import', '[email protected]');
Route::get('export', '[email protected]');

this is the routes


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

    <h1>إستيراد وتصدير الملفات</h1>

    <form action="{{ url('people/import') }}" method="POST" name="importform">
        @csrf
        <input type="file" name="import_file"><br /><hr />
        <button>إستيراد ملفات</button>
        <a href="url('export')">تصدير الملف</a>
    </form>

    <hr />
    <hr />
    <hr />

    <table border="1">
        <tr>
            <th>المحافظة</th>
            <th>المدينة</th>
            <th>الحي</th>
            <th>المحلة</th>
            <th>الزقاق</th>
            <th>رقم مركز التموين</th>
            <th>إسم مركز التموين</th>
            <th>رقم الصحيفة</th>
            <th>رقم السجل</th>
            <th>إسم الأب</th>
            <th>تاريخ التولد</th>
            <th>العمر</th>
            <th>الإسم</th>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </table>
    <hr />

</body>
</html>


this is the code view

Please sign in or create an account to participate in this conversation.