Template loads only in one view

Asked

Viewed 27 times

-3

Good night!

I created a directory called layouts and within it a template (template.blade.php) to use in my views whenever necessary, but it loads only in a view whose name is index.blade.php, already in another view called addOrcamento.blade.php does not load, follows the code

Tamplate.blade.php

<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <title>@yield('title')</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="{{'assets/css/bootstrap.min.css'}}">
    <link rel="stylesheet" href="{{'assets/css/estiloHeader.css'}}">
</head>
<body>
    <header>
        <nav class="navbar navbar-default navbar-fixed-top">
            <div class="container-fluid" >
                <div class="container">
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="navbar-header">
                                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavBar">
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                </button>
                                <a class="navbar-brand">Oficina <span class="glyphicon glyphicon-cog logo-small" style="color:#FFF;font-size:22px"></span></a>
                            </div>
                            <div class="collapse navbar-collapse" id="myNavBar">
                                <ul class="nav navbar-nav navbar-right">
                                    <li><a href="{{route('addOrcamento')}}">Cadastrar Orçamento</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </nav>
    </header>
    <article>
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    @yield('content')
                </div>
            </div>
        </div>
    </article>
    <footer>
        <div class="row">
            <div class="col-lg-12 text-center">
                 Todos os direitos reservados || Oficina 2.0
            </div>
        </div>
    </footer>
    <script type="text/javascript" src="{{'assets/js/query-3.1.1.min.js'}}"></script>
    <script type="text/javascript" src="{{'assets/js/bootstrap.min.js'}}"></script>
</body>
</html>

index.blade.php

@extends('layouts.template')
@section('title','orçamentos')
    
@section('content')
<table class="table-reponsive">
        <table class="table table-striped table-hover">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>CLIENTE</th>
                    <th>VENDEDOR</th>
                    <th>DESCRICAO</th>
                    <th>DATA E HORA</th>
                    <th>VALOR</th>
                    <th>AÇÃO</th>
                </tr>
            </thead>
            @foreach ($data as $item)
                <tr>
                    <td>{{$item->id}}</td>
                    <td>{{$item->cliente}}</td>
                    <td>{{$item->vendedor}}</td>
                    <td>{{$item->descricao}}</td>
                    <td>{{$item->data_hora}}</td>
                    <td>{{$item->valor_orcamento}}</td>
                    <td>
                        <a href="{{route('editOrcamento',['id'=>$item->id])}}" class="btn-danger btn-sm">Editar</a> 
                    </td>
                </tr>
            @endforeach
        </table>
    </table>
@endsection

addOrcamento.blade.php

@extends('layouts.template')
@section('title','adiciona orcamento')
    
@section('content')
<form method="POST">
    @csrf
    <label for="cliente">Cliente</label>
    <input type="text" name="cliente" id="cliente"><br/><br/>

    <label for="vendedor">vendedor</label>
    <input type="text" name="vendedor" id="vendedor"><br/><br/>

    <label for="descricao">descricao</label>
    <input type="text" name="descricao" id="descricao"><br/><br/>

    <label for="data_hora">data e hora</label>
    <input type="date" name="data_hora" id="data_hora"><br/><br/>

    <label for="valor_orcamento">valor do orcamento</label>
    <input type="text" name="valor_orcamento" id="valor_orcamento"><br/>

    <input type="submit" value="cadastrar">
</form>
@endsection

1 answer

0


If you want to load two views simultaneously you need to create them as a different name @Section('content') and @Section('content1'), then you can add 2 includes.

If you want to load another one depending on where the user clicks you should fix it in the controller. For example in the section:

<div class="collapse navbar-collapse" id="myNavBar">
 <ul class="nav navbar-nav navbar-right">
  <li><a href="{{route('addOrcamento')}}">Cadastrar Orçamento</a></li>
 </ul>

You can put the route as <a href="{{route('addOrcamento.index')}}"> and in the index function of the control of addOrcamento you put a return view ('caminho da sua view aqui') So this same content can be changed depending on the click.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.