Hello! The problem is in the namespace of the product.php file and in the "Use Stock \ Product;" of the controller.
I see 2 solutions for your code compiling without errors, they are:
Use the default laravel file structure
Create a namespace to allocate your "Product.php" file (which I think is what you tried to do)
Solution 1 (Use standard laravel framework)
In this larvavel solution create the models in the root of the "app" folder so that autoload works correctly you need to set the namespace of those files to reflect this structure.
Open Product.php file and change
DE:
use stock \ Product;
TO:
App \ Product;
After this open the App / Http / Controllers / ProductController.php file and change
DE:
use stock \ Product;
TO:
use App \ Product;
The final code should be:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use App\Produto;
use Request;
class ProdutoController extends Controller {
public function lista(){
$produtos = Produto::all();
return view('produto.listagem')->with('produtos', $produtos);
}
}
and
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Produto extends Model {
protected $table = 'produtos';
//
}
Solution 2 (Create an "Inventory" namespace)
The tip is the same as the previous solution, your namespace (in this case) has to reflect the folder structure.
If you want to create a namespace named "Stock", I suggest creating a folder inside the "App" folder with the name "Stock", then move the "Product.php" file into the newly created folder and edit the namespace of the same to "App \ Inventory" logo and then open file "ProductController" and edit the "use" section
DE:
use stock \ Product;
To:
use App \ Stock \ Product;
The final structure would look like this:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use App\Estoque\Produto;
use Request;
class ProdutoController extends Controller {
public function lista(){
$produtos = Produto::all();
return view('produto.listagem')->with('produtos', $produtos);
}
}
and
<?php
namespace App\Estoque;
use Illuminate\Database\Eloquent\Model;
class Produto extends Model {
protected $table = 'produtos';
//
}
The folder structure will look similar to this
+ estoque
...
+ app
...
+ Http
+ Estoque
- Produto.php
...