5
<?php
namespace Laravel\Horizon\Http\Controllers;

class HomeController extends Controller
{
      /**
      * Single page application catch-all route.
      * @return \Illuminate\Http\Response
      */
      public function index()
      {
         return view('horizon::app'); // what's the meaning of this 'horizon::app'
      }
}

I found this syntax in the Laravel-Horizon Controller, can anyone explain this:

view('horizon::app');

What is the meaning of 'horizon::app'?

Lejiend
  • 1,219
  • 2
  • 16
  • 24

3 Answers3

4

Like others answers stated, that is known as view namespaces. It not limited to the package's view, but you can use it inside your project as well.

As example you might have admin and customer module and want to differentiate their view by their own folder name, at this point you could use the namespace declaration. As example you might have these folders structures:

|- resources
   |- views
      |- admin
         |- index.blade.php 
      |- customer
         |- index.blade.php  

Then you could register your own namespace that point to that particular folder path in AppServiceProvider.php:

app('view')->addNamespace('admin', base_path() . '/resources/views/admin');

// or

app('view')->addNamespace('customer', base_path() . '/resources/views/customer');

And later on, inside controller's method, you can reference it using:

return view("admin::index"); 

// or

return view("customer::index");
Norlihazmey Ghazali
  • 9,000
  • 1
  • 23
  • 40
2

:: is the scope (namespace) operator. Meaning app is declared within horizon.

Example (from php.net):

<?php
class MyClass {
    const CONST_VALUE = 'Un valor constante';
}

$classname = 'MyClass';
echo $classname::CONST_VALUE; // A partir de PHP 5.3.0

echo MyClass::CONST_VALUE;
?>
bcr
  • 950
  • 8
  • 28
2

This syntax indicates that the View named app belongs to the horizon package. Think of it as package::view.path.

More info in Laravel's Package Development documentation.

To register your package's views with Laravel, you need to tell Laravel where the views are located.

Package views are referenced using the package::view syntax convention. So, once your view path is registered in a service provider, you may load the admin view from the courier package like so:

Route::get('admin', function () {
    return view('courier::admin');
});

This feature used to be called view namespaces, if you've seen that term or want something else to search for. :)

Community
  • 1
  • 1
Aken Roberts
  • 13,012
  • 3
  • 34
  • 40