WEB DEVELOPER SITE
TUTORIALS HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Laravel - Namespaces


Namespaces are utilized in different programming dialects to make a different gathering of variable, capacities and classes. A program may contain different capacities and this may result in strife with existing functions.

Declaration of namespace

Namespaces can be characterized as a class of components in which every component has a remarkable name to that related class. It might be imparted to components in other classes.

You can proclaim a namespace as appeared in the grammar given underneath −

use <namespace-name>; 

Please note that the use catchphrase enables the designers to abbreviate the namespace. The default namespace utilized in Laravel is app, anyway a client can change the namespace to coordinate with a web application.

You can make a client characterized namespace by utilizing artisan order as appeared underneath −

On giving the above direction, you can watch the yield as appeared in the accompanying screen capture − The namespace once made can incorporate different functionalities which can be utilized in controllers and different classes. The code made based on namespace in controller and bit with documents to be specific application/comfort/kernel.php and application/Http/controller.php are appeared as follows

Kernel.php

<?php 

namespace Tutorialspoint\Console; 

use Illuminate\Console\Scheduling\Schedule; 

use Illuminate\Foundation\Console\Kernel as ConsoleKernel; 

class Kernel expands ConsoleKernel{ 

/** 

* The Artisan directions given by your application. 

* 

* @var cluster 

*/ 

secured $commands = [ 

/ 

]; 

/** 

* Define the application's order plan. 

* 

* @param \Illuminate\Console\Scheduling\Schedule $schedule 

* @return void 

*/ 

secured work schedule(Schedule $schedule){ 

/$schedule->command('inspire') 

/ - >hourly(); 

} 

/** 

* Register the Closure based directions for the application. 

* 

* @return void 

*/ 

ensured work commands(){ 

require base_path('routes/console.php'); 

} 

} 

Note that the capacities to be specific timetable and directions helps in booking techniques for Cron occupations and other functionalities.

Controller.php

<?php 

namespace Tutorialspoint\Http\Controllers; 

use Illuminate\Foundation\Bus\DispatchesJobs; 

use Illuminate\Routing\Controller as BaseController; 

use Illuminate\Foundation\Validation\ValidatesRequests; 

use Illuminate\Foundation\Auth\Access\AuthorizesRequests; 

class Controller expands BaseController{ 

use AuthorizesRequests, DispatchesJobs, ValidatesRequests; 

} 

The controllers go about as a go-between among models and perspectives. For the namespace which we made called Tutorialspoint, they will be utilized in center record of controllers controller.php. The namespace is introduced appropriately with Http\Controllers.

The namespace once made utilizations different namespaces like AuthorizesRequests, DispatchesJobs and ValidatesRequests as referenced in the above code.