cac
1 year ago
119
11
Laravel

Blade file not rendering <script></script> L5.7

Posted 1 year ago by cac

I have a script tag (pure javascript) appended to the end of my html and it is not rendering the script tag. I used to simply open a script tag in older versions of laravel but now in this version it is not working. Does anyone have a clue?

@extends('layouts.app')
@section('content')
    @if(session('msg'))
        <div class="alert alert-danger">
            <p>{{session('msg')}}</p>
        </div>
    @endif
    @if($cars)

        <div class="row">
            <input id="term" name="term" autofocus placeholder="Buscar" type="text" class="form-control">

        </div>
        <br>
        <div class="row">
            <table id="table" class="table table-sm  table-condensed table-hover">
                <caption>List de Carros</caption>
                <thead class="thead-dark">
                <tr>
                    <th>#</th>
                    <th>Modelo</th>
                    <th>Quantidade</th>
                    <th>Marca</th>
                    <th>Preço</th>
                    @if(Auth::user()->isAdmin())
                        <th>Ações</th>
                    @endif

                </tr>
                </thead>
                <tbody>
                @foreach($cars as $car)
                    <tr>
                        <td>{{$car->id}}</td>
                        <td>{{ $car->model }}</td>
                        <td>{{ $car->quantity }}</td>
                        <td>{{ $car->brand->name }}</td>
                        <td>R$ {{ $car->price }}</td>
                        @if(Auth::user()->isAdmin())
                            <td>
                                <a href="{{route('cars.edit',$car->id)}}">
                                    <button class="btn btn-sm btn-primary" type="button">Editar</button>
                                </a>
                                <form method="POST" action="{{route('cars.destroy',$car->id)}}">
                                    @method('DELETE')
                                    @csrf
                                    <button class="btn btn-sm btn-danger" type="submit">Deletar</button>
                                </form>
                            </td>
                        @endif
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
        <script>
            function filterTable(event) {
                debugger;
                var filter = event.target.value.toUpperCase();
                var rows = document.querySelector("#table tbody").rows;
                for (var i = 0; i < rows.length; i++) {
                    var firstCol = rows[i].cells[0].textContent.toUpperCase();
                    var secondCol = rows[i].cells[1].textContent.toUpperCase();
                    var thirdCol = rows[i].cells[4].textContent.toUpperCase();
                    if (firstCol.indexOf(filter) > -1 || secondCol.indexOf(filter) > -1 || thirdCol.indexOf(filter) > -1) {
                        rows[i].style.display = "";
                    } else {
                        rows[i].style.display = "none";
                    }
                }
            }

            document.querySelector("#term").addEventListener('keyup', filterTable, false);
        </script>
    @else
        <div class="text-center">
            <p>Nenhum registro encontrado</p>
        </div>
    @endif

@endsection


Please sign in or create an account to participate in this conversation.