Support the ongoing development of Laravel.io →
posted 1 year ago
Laravel
Last updated by @tvbeek 1 year ago.
0
moderator

Hello @funkyfela

Can you tell us what the error is?

I found this line a little bit strange: $result = (new CategoryController)->Category()
You create your CategoryController and call the Category function on it. It isn't impossible but normally you don't create a controller class in another controller.

My guess is that you want to load the Categories in your controller and show them on your form.

If that is what you want to have you can do it like this:

public function create() {
    return view('products.create', [
        'categories' => Category::all(), //load all the categories from the database
    ]);  
}

Ps. I have updated your formatting a little bit :)

khatriafaz, funkyfela, frankdev-327 liked this reply

3

Hello @tvbeek Thanks for your reply. I was doing the wrong thing all these while! Thanks so much.

Just started learning laravel.

Thanks so much!

tvbeek, funkyfela liked this reply

2

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.