Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel syntax '::' at view function meaning

<?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'?

like image 416
Bathulah Mahir Avatar asked May 03 '18 03:05

Bathulah Mahir


People also ask

What does view do in Laravel?

What are the views? Views contain the html code required by your application, and it is a method in Laravel that separates the controller logic and domain logic from the presentation logic. Views are located in the resources folder, and its path is resources/views.

What is View Composer in Laravel?

View Composers are callback or a class method that gets executed when a view is rendered. That means when Laravel loads a *. blade. php file to serve to the browser to display contents it executes View Composers.

What is view in MVC Laravel?

MVC Architecture Of Laravel Model (M)–A model handles data used by the web application. View (V)–A view helps to display data to the user. Controller (C)–A controller interacts with the model to create data for the view.

What is :: In Laravel?

Basically its know as Scope resolution operator (::) Simply it is token which allow access to static, constant and overridden properties of method of a class. Example- in laravel we call model like this.


1 Answers

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");
like image 99
Norlihazmey Ghazali Avatar answered Oct 10 '22 21:10

Norlihazmey Ghazali