Use of unassigned variable '$product' PHP(PHP1412)
ahmadengali opened this issue · comments
using vsc 1.87.2
to define an api project over Laravel 10
in the file " productcontroller.php" , I'v define all the needed values , like " $product " variable as shown below
'' " " public function index()
{
return product::all();
}
public function store(Request $request)
{
$validated = $request->validate([
'name' => 'required|max:255',
'description'=>'required',
'price'=>'required | numeric',
]);
$product = Product::create($validated);
return response()->Json($product, 201);
}
public function show()
{
return response()->Json($product, 200);
}
Expected behavior
the var : "$product" gives " ' Use of unassigned variable '$product' PHP(PHP1412) ' in the line :
// return response()->Json($product, 200); // !
**php PHP 8.2.12 (cli)
OS windows 10 / Intelephense version: 1.25.0
can some help please.. thank you.
Looks like a valid error to me. Either way it is coming from a different extension.