Call to a member function getClientOriginalName() on null

I want to data insert with image for this i write a programe but error show

Call to a member function getClientOriginalName() on null

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Memberregistration;

class memberinsertcontroller extends Controller
{

public function store(Request $request){

$memberpic = $request->file(‘upload_file’);
$name = $memberpic->getClientOriginalName();
$uploadpath = ‘public/uploadpic/’;
$memberpic->move($uploadpath,$name);
$imageurl = $uploadpath.$name;

$Registration = new Memberregistration();
$Registration->name = $request->name;
$Registration->fathername = $request->fathername;
$Registration->address = $request->address;
$Registration->date = $request->date;
$Registration->email = $request->email;
$Registration->mobile = $request->mobile;
$Registration->porpuse = $request->porpuse;
$Registration->image = $imageurl;
$Registration->save();

}

//
}

Hi @benjir01,

This post was moved to a different board that fits your topic of discussion a bit better. This means you’ll get better engagement on your post, and it keeps our community organized so users can more easily find information.

As you’ll notice, your topic is now here in the Project Development Help and Advice board. No action is needed on your part; you can continue the conversation as normal here.

Cheers!

$memberpic = $request->file('upload_file');

The file() method may return a file, an array, or null. So you want to check for null before trying to use $memberpic.

I’m not sure how to suggest diagnosing why the Request doesn’t have a file.

2 Likes