@khaledalsamman enctype="multipart/fomr-data" should be enctype="multipart/form-data" :)
Apr 11, 2021
3
Level 1
Call to a member function store() on null
so, i am using laravel 8 to import an excel file into my db and from there display the data. its my first time dealing with any file upload in laravel an di am really lost.
here is my form :
<form class="formCus" method="post" action="/import" enctype="multipart/fomr-data" >
{{ csrf_field() }}
<label class="formItem" for="fileUpload">Upload your excel file: </label>
<input class="formItem" type="file" name="excelFile" id="file" >
<button class="formItem" type="submit">Upload File</button>
</div>
and my Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Employees;
use Maatwebsite\Excel\facades\Excel;
use App\Imports\EmployeesImport;
class EmployeeController extends Controller
{
public function index(){
$employees = new Employees;
return view('welcome');
}
public function import(Request $req){
$req->validate([
'excelFile' => 'required'
]);
$path1 = $req->file('excelFile')->store('/','public');
$path=storage_path('app').'/'.$path1;
Excel::import(new EmployeesImport, $path);
return view('welcome');
}
public function export(){
dd("Export");
}
}
Please or to participate in this conversation.