What’s New in Laravel 5
1. Directory Structure
The envelope structure of a Laravel venture has experienced a noteworthy update. Laravel 5 implements the PSR-4 autoloading standard, which implies every one of your classes are totally namespaced. The default namespace for your web application is app, which you can change utilizing the php artisan app:name <your-application name> command.
Your models fall under the default app namespace and are inside the application organizer. Your application’s advantages, perspectives, and dialect records are in the assets envelope(folder).The vendor, public,and bootstrap registries hold their place as in the more seasoned adaptations of the structure, while the config, stockpiling, database, and tests indexes have been moved to the base of the task.
On the off chance that you look inside the application envelope, you will see a great deal of classes, however don’t stress over them for the time being—we are going to get into that throughout this articl
Environment location has been immensely moved forward. Rather than all the complex settled design registries, you have an .env record at the foundation of your undertaking to deal with the application environment and all the environment variables. Additionally, the php artisan tinker summon now uses the Psysh bundle rather than Boris..
2. Method Injection
System infusion has been extraordinarily rearranged. Until variant 4.2, you needed to ask for the Inversion of Control (IoC) compartment to give a class case or make it in your controller’s constructor to make it available under the class scope. Presently, you can declare the type hinted class example in the controller system’s mark and the IoC compartment will deal with it, regardless of the possibility that there are various parameters in your controller capacity’s mark
// your class at "app/Classes/your_class.php"
// your class implementation
// somewhere in one of your controller actions
// use $MyObject just like any other object
4. Route Caching
Artisan has another route caching feature. Route reserving massively accelerates your application’s route registration, with unmistakably noticeable execution advantages. Be that as it may, if your application bargains in a little number of routes, you won’t not see the effect route storing should have, which implies it is more suited to situations where your application has an large number of routes
The commands php artisan route:cache and php artisan route:clear turn course storing on and off respectively. Once route storing is turned on, any adjustments you make to the application routes won’t produce results. Route caching would by and large be actualized as a feature of your arrangement process
5. Route Middleware
Middleware can be utilized to add additional layers to your HTTP routes. On the off chance that you need code to execute before each routesor before particular routes in your application, then such a bit of code is a solid match for a middleware class.
For instance, suppose you need to shut out a certain range of IPs from your application to make your application unavailable in that region. In such a case, you should check the client IP before every request and allow/disallow them entry to your application. This will be a considerable measure to do in your controller actions, so you will utilize middleware. Create a middleware class at
app/Http/Middleware/RegionMiddleware.php by using
php artisan make:middleware "RegionMiddleware"
* Handle an incoming request.
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
// perform some IP logic on $request
// and redirect to appropriate
// page based on results
// everything went well
// this will resume normal flow
You can then register your middleware in the app/Http/Kernel.php file by appending it to the $middleware array. In such a case, you should check the client IP before every request and allow/disallow them entry to your application. This will be a considerable measure to do in your controller actions, so you will utilize middleware. Create a middleware class at