1

Ive problems using livewire. All works fine, but when I type the input, data refresh and dissapear data from views/livewire/filtro. When I click on url, data comes well. Ive to refresh url to view data. Ive tried displya blade without Front Controller, clear cache, clear routes

Http/Livewire/Filtro

use Livewire\WithPagination;

class Filtro extends Component
{

use WithPagination;

protected $paginationTheme = 'bootstrap';

protected $queryString = ['marca'];
public $marca;

public function render()
{
    return view('livewire.filtro', [
        'productos' => Producto::where('deleted',0)
                            ->where('marca', 'like', '%'.$this->marca.'%' )->paginate(20)
    ]);
}
}

routes/web

<?php

use Illuminate\Support\Facades\Route;

/*
Web Routes
--------------------------------------------------------------------------
*/

// Localized
Route::localized(function () {

Route::get('/anuncios', function () {
return view('front.anuncios');
});

Route::get('/', function () {
return view('front.index');
});

Route::get('/index', [App\Http\Controllers\FrontController::class, 'index'])->name('front.index');

});

Auth::routes();


Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

Route::fallback(\CodeZero\LocalizedRoutes\Controller\FallbackController::class)
->middleware(\CodeZero\LocalizedRoutes\Middleware\SetLocale::class);

views/livewire/filtro


    <div class="listing__text__top">
        <div class="listing__text__top__left">
            <h5>Todoterrenos</h5>
            <span>{{ $productos->count() }} Resultados</span>
            <input type="text"  class="form-control" placeholder="Search" wire:model.debounce.1000ms="marca" />
            <div wire:loading>
    Processing ...
            </div>
            <div wire:offline>
You are now offline.
        </div>
        <div class="listing__text__top__right">Ordenar <i class="fa fa-sort-amount-asc"></i></div>
    </div>
@if($productos->count()) @foreach($productos as $producto)
                  @if($producto->garantizado === 'Si')
                    <div class="listing__item__text__info__right pr-3">Garantizado</div>
                  @endif

            <div class="">

            <a href="{{ route('front.detalle', $producto->titulo_slug) }}"><img src="{{ asset('img/productos/'.$producto->imagen_1)}}" height="150" alt="..." class="rounded float-left pr-2"></a>
            </div>
            <div class="listing__item__text">
                <div class="listing__item__text__inside ">
                    <h5><a href="{{ route('front.detalle', $producto->titulo_slug) }}">{{ $producto->titulo }}</a></h5>

                    <div class="listing__item__text__rating">
                       
                        <span>{{ number_format($producto->km,0,',','.') }} km</span>

                        <h6>{{ number_format($producto->precio_contado,0,',','.' ) }} &euro;</h6>
                    </div>
                    <ul>
                       
                        <li><i class="fa fa-map-marker"></i> {{ $producto->municipio }}, {{ $producto->municipio_slug }}</li>
                       
                    </ul>
                </div>   
            </div>
        </div>
@endforeach
@else

No hay productos

@endif

{{ $productos->links() }}

App/Http/Comtrollers/FrontController


namespace App\Http\Controllers;

use App\Models\Front;
use Illuminate\Http\Request;

use Illuminate\Support\Facades\DB;

use App\Models\Producto;
use App\Models\Link;
use Illuminate\Support\Facades\Session;

use App;

class FrontController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/

 public function anuncios()
{
    return view('front.anuncios');
}

 public function index()
{
    return view('front.index');
}



public function detalle($titulo_slug)
{

 //   dd($titulo_slug);

  if($titulo_slug !='index' && $titulo_slug !='blog'){

    $producto = Producto::where('titulo_slug',$titulo_slug)
                            ->first();

    $num = $producto->visitas;

      $num ++;

      $producto->visitas = $num ;

      $producto->save();                        


    return view('front.detalle')->with('producto',$producto);
                            }
                            
}

public function locale($lang)
{
       App::setlocale($lang);

        session(['locale' => $lang]);
    
    return view('front.index');
}

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
    //
}

/**
 * Remove the specified resource from storage.
 *
 * @param  \App\Models\Front  $front
 * @return \Illuminate\Http\Response
 */
public function destroy(Front $front)
{
    // 
}
}
Ivan
  • 19
  • 3
  • The first thing I see is that your view has more than 1 root element. It should be entirely wrapped in one big `
    `.
    – Qirel May 26 '22 at 20:01
  • Also worth reading https://laravel-livewire.com/docs/2.x/troubleshooting#dom-diffing-issues – Qirel May 26 '22 at 20:01
  • SOLVED ¡¡¡ Thanks to @Qirel. The problem was that views/livewire/filtro was not all inside a
    ,
    – Ivan May 27 '22 at 11:42

0 Answers0