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

mhmmdva's avatar

Target [App\Http\Controllers\Client\ProductController] is not instantiable.

i have problem with this error, but i don't know how to resolve

0 likes
22 replies
Sinnbeck's avatar

Show that contoller. Most likely its abstract or an interface

mhmmdva's avatar

@Sinnbeck

OK ! thanks

i just need to use this code :

public function __construct(private ProductService $productService) { // }

Sinnbeck's avatar

@mhmmdva Please format it

Add ``` on the line before and after your code

And be aware that you already set the thread as solved. I assume thats a mistake?

mhmmdva's avatar

@Sinnbeck sorry i do not understand about this

Add ( ``` ) on the line before and after your code

mhmmdva's avatar

@Sinnbeck product controller


<?php

namespace App\Http\Controllers\Client;

use App\Http\Controllers\Controller;
use App\Http\Requests\ProductRequest;
use App\Models\Product;
use App\Services\ProductService;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;


class ProductController extends Controller

{   
    private function __construct(private ProductService $productService)
    {
    
        $this->productService = $productService;
    
    }  
   
    public function index(): View
    {
        $products = Product::get();

        return view('client.product.index', [
            'products' => $products,
        ]);
    }

    public function show()
    {
    }

    public function create(Product $product): View
    {
        return view('client.product.create', [
            'product' => $product,
        ]);
    }

    public function store(ProductRequest $productRequest): RedirectResponse
    {
        $this->productService->handleStore($productRequest);

        return to_route('client.product.index')->with('success', 'Congratulation you have successfully added product !');
    }

    public function edit(Product $product)
    {
        return view('client.product.edit', [
            'product' => $product,
        ]);
    }

    public function update(Product $product, ProductRequest $productRequest): RedirectResponse
    {
        $this->productService->handleUpdate($productRequest, $product);

        return to_route('client.product.index')->with('success', 'Congratulation you have successfully added product !');
    }

    public function destroy(Product $product): RedirectResponse
    {
        $this->productService->handleDestroy($product);

        return to_route('client.product.index')->with('success', 'Congratulation you have successfully added product !');
    }

}


mhmmdva's avatar

Sorry for the first time I used Laracast

Sinnbeck's avatar

@mhmmdva No worries. Try changing the constructor to public

 public function __construct(private ProductService $productService)
1 like
Tray2's avatar
Tray2
Best Answer
Level 73

@mhmmdva Try changing this

   private function __construct(private ProductService $productService)
    {
    
        $this->productService = $productService;
    
    }  

To this

public function __construct(private ProductService $productService)
    {
    }  
1 like
Tray2's avatar

Share the code in that class.

Sinnbeck's avatar

@mhmmdva Great. Please mark a best answer to set the thread as solved then :)

1 like
johnDoe220's avatar

You probably defined your constructor as private.If you intend to inherit, you should know that you cannot inherit from private, the best option is protected so that you can inherit if you need to.

1 like

Please or to participate in this conversation.