title: Access controller variable directly inside component class - Laravel
body: <p>Normally we pass the parameter from controller into x component like <code>&lt;x-book-list books=&quot;$books&quot; /&gt;</code> and access it in BookList Class as below</p>
  <pre class="lang-php prettyprint-override"><code>
  namespace App\View\Components;
  
  use Illuminate\View\Component;
  
  class BookList extends Component
  {
      public $books;
      
      /**
       * BookList Component
       *
       * @param array $book
       *
       * @return void
       */
      public function __construct(array $books)
      {
          $this-&gt;books = $books;
      }
  
  
  </code></pre>
  <p>I use this kind of component in my app repeatedly but here, I want to make it a bit cleaner without adding <code>books</code> attribute every-time I call it because they are definitely the same everywhere.</p>
  <p>So, can I access the <code>books variable</code> inside Book component class without passing through <code>&lt;x-book-list /&gt;</code>?</p>
  <p>Probably something as below.</p>
  <pre class="lang-php prettyprint-override"><code>
  namespace App\View\Components;
  
  use Illuminate\View\Component;
  
  class BookList extends Component
  {
      public $books;
      
      /**
       * BookList Component
       *
       * @param array $book
       *
       * @return void
       */
      public function __construct()
      {
          // How to access $book variable directly from controller without passing from &lt;x-booklist /&gt; ????
      }
  
  
  </code></pre>