Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

spAo's avatar
Level 1

Trying to store image

Hello i'm trying to store my quizzes image it's uploads image but i can't found image in my project folder but in database i can see that in image field there is uploaded image image.jpg Then i added this

request()->file('image')->store('public/quizzes');

But now i'm getting error Call to a member function store() on null

full store function:

 public function store(Quizze $quizzes)
    {
        $data = request()->validate([
            'quizzes.title' => 'required',
            'quizzes.image' => '',
            'questions.*.question' => 'required',
            'questions.*.answers.*.answer' => 'required',
            'questions.*.answers.*.correct' => '',
        ], [
            'quizzes.title.required' => 'გთხოვთ, შეიყვანოთ ქვიზის სახელი.',
            'questions.*.question.required' => 'გთხოვთ, შეიყვანოთ შეკითხვა.',
            'questions.*.answers.*.answer.required' => 'გთხოვთ, შეიყვანოთ პასუხი.'
        ]);
        request()->file('image')->store('public/quizzes'); // not working - but without it it's works
        $storeQuiz = $quizzes->create($data['quizzes']);
        foreach ($data['questions'] as $key => $q) {
            $question = $storeQuiz->questions()->create(['question' => $q['question']]);
            $question->answers()->createMany($data['questions'][$key]['answers']);
        }
        return redirect('admin/quizzes')->with('success', 'ქვიზი წარმატებით დაემატა.');
    }

without request image and store function it's creates but in image fields i think it's getting only image name not a image. I searched and it's very easy to store image but how can i store image in this store function...

0 likes
1 reply
martinbean's avatar

@spao Your controller seems a bit of a mess. You have (empty) validation for a field quizzes.image, but then try and read a file with the name of just image. So yes, it’ll be null if you’re trying to access the image with an incorrect name.

Please or to participate in this conversation.