Show that contoller. Most likely its abstract or an interface
Target [App\Http\Controllers\Client\ProductController] is not instantiable.
i have problem with this error, but i don't know how to resolve
@mhmmdva Add ``` on the line before and after your code
OK ! thanks
i just need to use this code :
public function __construct(private ProductService $productService) { // }
@mhmmdva ok? And without that the error goes away? Do you have php 8?
The problem is still there, yes I have PHP 8
@mhmmdva So please show the controller
this is product controller
@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?
@Sinnbeck sorry i do not understand about this
Add ( ``` ) on the line before and after your code
@mhmmdva An example
```
your code
```
@Sinnbeck its error
@mhmmdva I dont know what that means
@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 !');
}
}
Sorry for the first time I used Laracast
@mhmmdva No worries. Try changing the constructor to public
public function __construct(private ProductService $productService)
@mhmmdva Try changing this
private function __construct(private ProductService $productService)
{
$this->productService = $productService;
}
To this
public function __construct(private ProductService $productService)
{
}
Share the code in that class.
class ? maybe, product controller ?
@mhmmdva Yes which else?
@mhmmdva Great. Please mark a best answer to set the thread as solved then :)
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.
Please or to participate in this conversation.