Rahul Savaliya
Rahul Savaliya

Reputation: 138

Livewire - Passing Data To View & Component from URL

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>

Upvotes: 0

Views: 1047

Answers (1)

mohammad hossein goli
mohammad hossein goli

Reputation: 71

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

Upvotes: 1

Related Questions