Home > front end >  Livewire - Passing Data To View & Component from URL
Livewire - Passing Data To View & Component from URL

Time:12-09

I need to pass my data from the url and it works in the console log, but something happened to the view, it does not render the variable and the view loads just the footer, can anyone help me out please?

web routes:

Route::view('/aplicacion', 'application.visa-americana');
Route::get('/aplicacion/{id}', VisaUsaComponent::class);

layout:

@extends('layouts.app')

@section('content')
{{-- livewire interactions --}}
      @livewire('applications.visa-usa-component')
@stop

Component:

use App\Models\User;
use Livewire\Component;

class VisaUsaComponent extends Component
{
 
  public $post;

public function mount($id)
  {
    $this->post = User::findOrFail($id);
  }

  public function render()
  {
    return view('livewire.applications.visa-usa-component');
  }
}

View:

<div>
      {{ $post->name }}
</div>

CodePudding user response:

try this:

public function render()
  {
    return view('livewire.applications.visa-usa-component')->layout('your layout address')->section('content');
  }

Livewire use {{$slot}} for render and app.blade.php for layout, if you want change them, you must pass to render function

don't forget use @livewireScripts and @livewireStyles in app.layout.php

  • Related