search

Home  >  Q&A  >  body text

Undefined variable in component

My server works in Linux via apache2, but works fine in development environment via artisan service on a Windows machine.

The error isUndefined variable $washProgram

<div>
   Programa {{ $washProgram->name }}
</div>
<?php

namespace App\View\Components;

use Illuminate\View\Component;

class expeditionData extends Component
{

    public $op;
    public $washProgram;

    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct($op)
    {
        $this->op = $op;
        $this->washProgram = $op->getSelectedWashProgram();
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\View\View|string
     */
    public function render()
    {
        return view('components.expedition-data');
    }
}
<x-expedition-data :op="$op" />

I want to generate a view using this component but it gives me this error.

P粉709307865P粉709307865434 days ago826

reply all(1)I'll reply

  • P粉384366923

    P粉3843669232023-09-07 00:06:37

    Thank you so much. Linux is case sensitive. The component's file names have been changed so that they all begin with a capital letter:

    expeditionData.php -> ExpeditionData.php

    reply
    0
  • Cancelreply