Sounds like the request does not have an image. Can you show StorePostRequest?
Didn't this just work? What was changed?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
showing error on update
Call to a member function store() on null
Controler code
public function update(StorePostRequest $request, $id)
{
$data= $request->validated();
$data= Student::find($id);
$data['image'] = $request->file('image')->store('images', 'public');
Student::update($data);
session()->flash('success', 'Your record has been updated ☑️');
return redirect('/show');
}
Sounds like the request does not have an image. Can you show StorePostRequest?
Didn't this just work? What was changed?
@Sinnbeck request code
public function rules()
{
return [
'first_name' => 'required',
'last_name' => 'required',
'email' => 'required',
'contact' => 'required',
'address' => 'required',
'image' => 'required',
];
}
@Shivamyadav I assume you want images
'image' => 'required|image'
@Sinnbeck done request code
public function rules()
{
return [
'first_name' => 'required|min:3|max:30',
'last_name' => 'required|max:30',
'email' => 'required|email',
'contact' => 'required|numeric',
'address' => 'required|',
'image' => 'required|image',
];
}
@Shivamyadav you added a | to address? You can remove that or add an extra rule. Example
'address' => 'required|string',
@Sinnbeck now it showing a validation error of image whenever i select an image for the file it shows
The image must be an image.
@Shivamyadav can you show the form?
My guess is that it's missing enctype='multipart/form-data'
@Sinnbeck create form
@extends('layouts.app')
@section('content')
<div class=" flex justify-center">
<div class="w-2/4 bg-gray-200 p-2">
<h1 class="text-white p-5 text-lg text-center bg-green-600">
Add Students
</h1>
<form action="/student/create" method="POST" enctype="multipart/form-data">
@csrf
<div class="mt-3 ml-2 field">
<h4 class="mb-2 font-mono">First Name</h4>
<input type="text" name="first_name" class="w-full">
@error('first_name')
<span class="text-red-400">{{$message}}</span>
@enderror
</div>
<div class="mt-3 ml-2 field">
<h4 class="mb-2 font-mono">Last Name</h4>
<input type="text" name="last_name" class="w-full">
@error('last_name')
<span class="text-red-400">{{$message}}</span>
@enderror
</div>
<div class="mt-3 ml-2 field">
<h4 class="mb-2 font-mono">Email</h4>
<input type="email" name="email" class="w-full">
@error('email')
<span class="text-red-400">{{$message}}</span>
@enderror
</div>
<div class="mt-3 ml-2 field">
<h4 class="mb-2 font-mono">Contact No.</h4>
<input type="number" name="contact" class="w-full">
@error('contact')
<span class="text-red-400">{{$message}}</span>
@enderror
</div>
<div class="mt-3 ml-2 field">
<h4 class="mb-2 font-mono">Address</h4>
<input type="text" name="address" class="w-full">
@error('address')
<span class="text-red-400">{{$message}}</span>
@enderror
</div>
<div class="mt-3 ml-2 field">
<h4 class="mb-2 font-mono">Your Image</h4>
<input type="file" name="image" class="w-full">
@error('image')
<span class="text-red-400">{{$message}}</span>
@enderror
</div>
<div class="mt-2 ml-2">
<button class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
Submit
</button>
</div>
</form>
</div>
</div>
@endsection
Edit form goes here
@extends('layouts.app')
@section('content')
<div class=" flex justify-center">
<div class="w-2/4 bg-gray-200 p-2">
<h1 class="text-white p-5 text-lg text-center bg-green-600">
Edit Students
</h1>
<form action="/update/{{$students->id}}" method="POST">
@csrf
<div class="mt-3 ml-2 field">
<h4 class="mb-2 font-mono">First Name</h4>
<input type="text" name="first_name" class="w-full" value="{{ $students->first_name}}">
@error('first_name')
<span class="text-red-400">{{$message}}</span>
@enderror
</div>
<div class="mt-3 ml-2 field">
<h4 class="mb-2 font-mono">Last Name</h4>
<input type="text" name="last_name" class="w-full" value="{{ $students->last_name}}">
@error('last_name')
<span class="text-red-400">{{$message}}</span>
@enderror
</div>
<div class="mt-3 ml-2 field">
<h4 class="mb-2 font-mono">Email</h4>
<input type="email" name="email" class="w-full" value="{{ $students->email}}">
@error('email')
<span class="text-red-400">{{$message}}</span>
@enderror
</div>
<div class="mt-3 ml-2 field">
<h4 class="mb-2 font-mono">Contact No.</h4>
<input type="number" name="contact" class="w-full" value="{{ $students->contact}}">
@error('contact')
<span class="text-red-400">{{$message}}</span>
@enderror
</div>
<div class="mt-3 ml-2 field">
<h4 class="mb-2 font-mono">Address</h4>
<input type="text" name="address" class="w-full" value="{{ $students->address}}">
@error('address')
<span class="text-red-400">{{$message}}</span>
@enderror
</div>
<div>
</div>
<div class="mt-3 ml-2 field">
<h4 class="mb-2 font-mono">Your Image</h4>
<input type="file" name="image" class="w-full">
@error('image')
<span class="text-red-400">{{$message}}</span>
@enderror
</div>
<div class="mt-2 ml-2">
<button class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
Update
</button>
</div>
</form>
</div>
</div>
@endsection
@Shivamyadav so it's missing?
<form action="/update/{{$students->id}}" method="POST"
enctype="multipart/form-data">
@Sinnbeck yeah! done this thing now its showing this error
Non-static method Illuminate\Database\Eloquent\Model::update() cannot be called statically
@Sinnbeck controller code
public function update(StorePostRequest $request, $id)
{
$data= $request->validated();
$data= Student::find($id);
$data['image'] = $request->file('image')->store('images', 'public');
Student::update($data);
session()->flash('success', 'Your record has been updated ☑️');
return redirect('/show');
}
@Shivamyadav like this
public function update(StorePostRequest $request, $id)
{
$data= $request->validated();
$student= Student::find($id);
$data['image'] = $request->file('image')->store('images', 'public');
$student->update($data);
session()->flash('success', 'Your record has been updated ☑️');
return redirect('/show');
}
@Sinnbeck worked 💕
@Shivamyadav great 👍
@Sinnbeck Any idea ! sir how to get value image data which is stored in the database table at the time of editing the data . like we get the values of other field
{{ $student->address}}
how can we get image value like this
Please or to participate in this conversation.