Somewhere you are calling pathinfo and passing it an object, check your code, probably it will be in the web.php file
Feb 2, 2020
7
Level 11
pathinfo()
Hey Laravelers
I have this issue:
ErrorException
pathinfo() expects parameter 1 to be string, object given
this is the controller
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Session;
use Maatwebsite\Excel\Facades\Excel;
use File;
class PeopleController extends Controller
{
public function index()
{
return view('add-person');
}
public function import(Request $request){
//validate the xls file
$this->validate($request, array(
'file' => 'required'
));
if($request->hasFile('file')){
$extension = File::extension($request->file->getClientOriginalName());
if ($extension == "xlsx" || $extension == "xls" || $extension == "csv") {
$path = $request->file->getRealPath();
$data = Excel::import($path, function($reader) {
})->get();
if(!empty($data) && $data->count()){
foreach ($data as $key => $value) {
$insert[] = [
'name' => $value->name,
'address' => $value->address,
'phone' => $value->phone,
];
}
if(!empty($insert)){
$insertData = DB::table('people')->insert($insert);
if ($insertData) {
Session::flash('success', 'Your Data has successfully imported');
}else {
Session::flash('error', 'Error inserting the data..');
return back();
}
}
}
return back();
}else {
Session::flash('error', 'File is a '.$extension.' file.!! Please upload a valid xls/csv file..!!');
return back();
}
}
}
}
this is model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
class People extends Model
{
use Searchable;
protected $guarded = [];
}
this is view:
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
<title>Import</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
<!-- Styles -->
<style>
html, body {
background-color: #fff;
color: #636b6f;
font-family: 'Raleway', sans-serif;
font-weight: 100;
height: 100vh;
margin: 0;
padding: 5%
}
</style>
</head>
<body>
<div class="container">
<h2 class="text-center">
Laravel Excel/CSV Import
</h2>
@if ( Session::has('success') )
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<strong>{{ Session::get('success') }}</strong>
</div>
@endif
@if ( Session::has('error') )
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<strong>{{ Session::get('error') }}</strong>
</div>
@endif
@if (count($errors) > 0)
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<div>
@foreach ($errors->all() as $error)
<p>{{ $error }}</p>
@endforeach
</div>
</div>
@endif
<form action="{{ route('import') }}" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
Choose your xls/csv File : <input type="file" name="file" class="form-control">
<input type="submit" class="btn btn-primary btn-lg" style="margin-top: 3%">
</form>
</div>
</body>
</html>
I'm using laravel 6
Please or to participate in this conversation.