Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Articles Tagged ‘laravel’

Web site authentication with Laravel

Friday, July 3rd, 2015 by Servage
authenticationThe ability to register and login is the basis for many features on most websites. Therefore authentication is an issue which developers are confronted with in almost every single project. Thankfully the Laravel developers have realized this, and therefore made it very easy to implement authentication. Actually default Laravel installations ship with the required pieces already available. You just need to move a few things into place to make it work for your project. Laravel provides the required controllers for the authentication procedure, but there are no routes active for this purpose by default. This is to avoid opening your web site to authentication unless you want it. Therefore simply add the following ...

Understand service containers in Laravel

Friday, June 19th, 2015 by Servage
service-containerThe service container concept in Laravel is one of the most misunderstood parts of the framework. It is rather complex and abstract but for the enlightened it provides great extensibility to your code and a useful way of managing class dependencies. Furthermore the service container facilitates insulation between different classes, which can be advantageous for creating more stable code. Dependency injection The class dependencies are managed via class injection, which basically means you can tell a method which class you expect, where after it will create an instance of it, if none is passed. Technically speaking this is done by type-hinting the expected class name. The code below shows an example class which loads a ...

Understand service providers in Laravel

Thursday, June 4th, 2015 by Servage
service-providersThe so called service providers are the heartbeat of your Laravel application. They are the central element of the initialization process where all the relevant and required code is loaded by PHP. This includes all the essentials from the framework itself, but also any own and custom code you need to load. Bootstrap service providers During the initializing process the code bootstraps itself. That means it gets ready to go by registering service container bignings, event listeners, middleware, configuration and routes. Service providers are therefore a central place to setup your application. In the config/app.php you will find an array of providers listing all the service provider classes that are loaded during bootstrapping. ...

Working with Laravel views for HTML output

Monday, May 18th, 2015 by Servage
view-layersThe MVC pattern (Model, View, Controller) dictates a clear division between controller logic and view generation. It means that you strictly use the controller code to determine what backend actions to make in order to process a request, but then hand over the response generation to the view. I.e. you can process, validate and store data via the controller, but pass the final result over to the view, which creates the output to be sent back to the client. In Laravel this means that you end up returning a response from your controller, which sends relevant content to the client. The view is usually HTML output, because other response types would have different ...

Sending HTTP responses in Laravel

Sunday, May 3rd, 2015 by Servage
httpThe normal usage of Laravel on a website is that a client request to an endpoint results in a response, one way or the other. The request could be anything from a typical browser request for a given website for HTML or files, to an automated request from a client server to an API endpoint you publish for structured data responses like JSON or XML. Either way, at some point you need to create and return a response in your controller- and Laravel comes ready to do so with lots of options available. Responding from a route without a controller You can respond directly from a route, without making a controller and action method. ...

Working with Laravel request-data

Monday, April 20th, 2015 by Servage
request-programming-appIn previous articles the usage of the Laravel PHP framework was described up to the point of setting up the framework and getting a basic controller running via a HTTP route. This is the basis for getting anything working via a browser request to a Laravel powered website. However, requests can include much more information than the simple URL. Many kinds of data could be passed, depending on your use case. For example it could be cookie information used for user login handling or shopping cart storage, post form data for user submitted information, or get parameters to manipulate information display on the given page. All this information is available in ...

Using and building own middleware in Laravel

Tuesday, March 17th, 2015 by Servage
middlewareWith Laravel 5 there are new possibilities using middleware. Essentially HTTP middleware is taking any request and doing "something" with it. For example Laravel has native middleware that can check authentication and authorization, so the framework can determine if the user is logged in and may perform a given action. If not, the middleware can redirect the user to a login page or display a relevant message. If the user is allowed, the middleware will let the request proceed without intervention. Another example could be to check for SSL encryption status. Some pages may require unencrypted requests (http), some may require encrypted requests (https), and some may work with both. This depends ...

URL routing in Laravel

Friday, February 27th, 2015 by Servage
url-seoCreating good and meaningful URLs is an important part of every web project. You need to consider the logical structure of your URLs as well as their SEO impact. At the same time URLs should follow a specific structure and provide a meaningful aid for the user in understanding what to expect in return from the server for a given endpoint. Structuring the URL The old way of creating URLs for dynamic PHP-based sites was to route everything through a single index.php file, with corresponding parameters. An example of such an URL could be: The example above holds a few values and a session id. Nowadays the session identifier would likely be parsed through a ...

Homestead provides a ready development environment for Laravel

Friday, February 6th, 2015 by Servage
homestead-laravel-vagrantThe PHP framework Laravel is currently one of the most popular frameworks. It is widely adopted and liked for its ease of use and good learning curve. You can read about getting started with Laravel in one of our earlier blog posts. Nowadays being able to speed up development time is very important. Constant changes in available technologies and new trends online dictate a high pace of new things to follow or use for a while, until the next thing comes along. Missing out on new trends is dangerous, because users quickly penalize sites for being out of date or lacking user friendliness. We have previously covered how ...