Search code examples
laravel-livewire

Variables that are defined in Livewire component but can’t be accessed in Laravel blade file


I have a controller in already done in Livewire and I’m trying to create a new Laravel controller and corresponding Laravel blade file (the purpose is that I was asked to complete the form in Laravel and then migrate it to livewire), and the question is that is it possible to access those Livewire variables into a Laravel controller and blade or need to create the new blade file and controller in Livewire right away? because I am still new in Livewire

  public $application_type;
    public $token;
    public $application_id;

 public $creditRows = [];
    public $gigRows = [];
    public $invIncomeRows = [];
    public $loansRows = [];
  public function render()
    {
        $country = country('my');
        $states = $country->getDivisions();
        $income_informations = DB::table('income_informations')->get();
        $bank_names = DB::table('bank_names')->get();
        $salutations = DB::table('salutations')->get();
        $genders = DB::table('genders')->get();

        return view('livewire.individual-loan-application-form-component',
            compact('states', 'income_informations', 'bank_names', 'salutations', 'genders'));
    }

Thanks a lot


Solution

  • Livewire works the same as Laravel when it comes to passing variables; they share the variables to the given view. If you were to include child components or parts, then the variables would be accessible there. However if you want them in a completely different view, you'd need to redefine those variables in a different controller/Livewire component.