2
I need to recover a method in the controller and display in the view,
Controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Categoria;
use App\Models\Sessoes;
class todosProdutosController extends Controller{
public function categorias(){
$categorias = Categoria::where('nome', 'LIKE', '%a%')->get();
foreach ($categorias as $categoria) {
$categoriaNome = $categoria->nome;
$sessao = $categoria->sessoes; // posso adicionar condições
foreach ($sessao as $sessao_) {
$sessao_->nome;
}
return view('home.home', 'produto', $categoriaNome);
}
}}
And in my view it’s like this
<section id="produtos">
<div class="container">
<div class="row">
<div class="col-md-12">
{{ dd($categoriaNome) }}
</div>
</div>
</div>
Some help?
In the tags
foreach
you don’t need to add keys "{{"– arllondias
@Luigi Jordânio keeps returning me error >> Undefined variable: categories (View: F: xampp htdocs study Resources views home home.blade.php) where I may be missing?
– Cristiano Facirolli
I found the problem, is that he had an extra argument, thus: Return view('home.home', Compact('categories')); Thank you very much for your help =)
– Cristiano Facirolli