Search code examples
netbeans-8maatwebsite-excel

Need explanation on Maatwebsite Excel "From View" code


While researching on how I can import table listing data using collection + HTML view to an excel file, I came across maatwebsite/excel package. I managed to import the excel by following the documentation. However, I am not familiar with the code syntax used by the author. On this link, the author defines a function view() as seen in the code below:

public function view(): View
{
    return view('exports.invoices', [
        'invoices' => Invoice::all()
    ]);
}

I am not familiar with view(): View syntax. Can someone direct me to a proper documentation for this? And tell me how I can resolve this in Netbeans (See screenshot below)? Screenshot of Netbeans error

Please keep in mind, the code itself is working correctly and has no issues. I am able to download the excel file as per my requirements.

Using: Laravel 5.6, PHP 7.1.17, NetBeans 8.0.2, maatwebsite/excel 3.0

Any info on this is appreciated. Thanks in advance.


Solution

  • In PHP 7.0 and greater, we can define the return type. For example.

    function sum(): int {
    // function body.
    
    }
    

    And same goes for:

    public function view(): View

    This line says that the function view() only returns the View class object.