by Rob Hope via One Page Love
"Mr Branding" is a blog based on RSS for everything related to website branding and website design, it collects its posts from many sites in order to facilitate the updating to the latest technology.
To suggest any source, please contact me: Taha.baba@consultant.com
Monday, June 13, 2016
Take What You Can Carry
by Rob Hope via One Page Love
Laravel Doctrine – Best of Both Worlds?
Laravel Doctrine is a drop-in implementation of the famous ORM for the Laravel 5.X Framework, and a really interesting alternative to the default choice, Eloquent. In this article, we will learn how to use it, and when.
Why Doctrine, and not Eloquent?
Those of us who have used Laravel at least once, have probably used Eloquent. We all love its fluent and easy syntax, and we all know snippets like the following:
$user = new App\User;
$user->name = 'Francesco';
$user->email = 'francesco@foo.bar';
$user->save();
What we're using here is the so called "Active Record" pattern. A frequently used architectural pattern, named by Martin Fowler in his ultra-famous book "Patterns of Enterprise Application Architecture". To simplify and explain things, this pattern assumes that a single row in the database is treated like an object in our software. However, with time, this pattern encountered many criticisms:
-
Active Record is about a strong coupling between database operations and the classes in our software. For many little projects this approach is more than fine, but what if our software grows in complexity? We could stumble upon the need for more classes, not always related to a specific table in our database. There, Active Record doesn't help us achieve a good level of abstraction from the data source.
-
the other main criticism is a direct consequence of the first: testability. If the model is tightly coupled to the database, building a test without it can be more difficult. It has to be said that a part of this problem can be reduced (not solved) with mocking and a good use of dependency injection.
Now, in the same book we mentioned before, Martin Fowler explained another architectural pattern: the Data Mapper. The Data Mapper consists of the presence of an intermediate layer which, working in both directions, provides access to the data source on one hand, and a good abstraction from it on the other. This means that objects in the software are not closely related to the data source, with great improvement in terms of responsibility isolation. The result? The developer can now focus on building an object that is nearer to the real world situation, and not to the database system chosen for the job.
Eloquent is an implementation of the Active Record pattern, and Doctrine is an implementation of Data Mapper. Let's see how we can install Doctrine for Laravel, and how to configure and use it.
Installing Doctrine for Laravel
As usual, we will use Homestead Improved as a standard development environment for our tests.
Let's create a new Laravel project.
composer create-project laravel/laravel Project
Then, we enter our project's folder and add Laravel Doctrine as a dependency with Composer.
composer require "laravel-doctrine/orm:1.1.*"
We also need to add the following class to our service providers list, in the config/app.php
file:
LaravelDoctrine\ORM\DoctrineServiceProvider::class,
Also, we can register the three facades for the EntityManager, Registry and Doctrine in the same file:
'EntityManager' => LaravelDoctrine\ORM\Facades\EntityManager::class,
'Registry' => LaravelDoctrine\ORM\Facades\Registry::class,
'Doctrine' => LaravelDoctrine\ORM\Facades\Doctrine::class,
Finally, we can publish the dedicated config file:
artisan vendor:publish --tag="config"
We are done! Laravel Doctrine is completely installed and configured.
The Example Application - ToDo List!
In order to learn something more about Doctrine for Laravel, we are going to replicate an existing application example that uses Eloquent. What about the Intermediate Task List on Laravel's official site?
We will create a very basic multi-user task list. In this application, our user will be able to:
- log into their own area.
- list existing tasks.
- add a new task to the list.
- mark a task as done / not done.
- update an existing task in the list.
- delete an existing task from the list.
Obviously, every user will be able to see only their own tasks.
Let's change the application's namespace to TodoList
first.
artisan app:name TodoList
Ok, now we can start from the very basics of Doctrine. In Eloquent, we used models. How do we start now?
Entities!
In Doctrine we use Entities to represent our application objects. Unlike with Eloquent where the model extends a base Model
class, a Doctrine entity is a plain PHP class that does not extend anything.
Here's a first stub of the Task
entity:
<?php
namespace TodoList\Entities;
class Task
{
private $id;
private $name;
private $description;
private $isDone = false;
public function __construct($name, $description)
{
$this->name = $name;
$this->description = $description;
}
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function getDescription()
{
return $this->description;
}
public function setName($name)
{
$this->name = $name;
}
public function setDescription($description)
{
$this->description = $description;
}
public function isDone()
{
return $this->isDone;
}
public function toggleStatus()
{
if(!$this->isDone) {
$this->isDone = true;
} else {
$this->isDone = false;
}
}
}
Not bad as a beginning. Yes, it's a little more "verbose" than an Eloquent model. However, there is a specific reason for that. First of all, if we think about it, this is a plain PHP class. It says nothing about its implementation, has no extra responsibilities. Everything it does is strictly related to the task itself. That's a good thing, because this approach is more "compatible" with the Single Responsibility Principle.
But...
Where is the Database?
In Eloquent, models are just an interface to the database. With some "magic", sometimes without even writing a single line of code in the model, we can just start working with them. The only thing we have to do is design our database accordingly. With Doctrine, the key concept is a little bit different.
Here, we start designing our application from our classes which represent the "real world" problem we want to solve. Then, we bind our classes to tables, and properties to columns.
Continue reading %Laravel Doctrine – Best of Both Worlds?%
by Francesco Malatesta via SitePoint
MilesWeb Affordable Hosting is targeted at Startups – Signup and get a Free SSL
Big thanks to this weeks website and RSS Sponsor, MilesWeb – a leading hosting provider proudly based in India.
They specialize in cPanel Hosting, Reseller, VPS, Dedicated Servers, Domain Names and SSL Certificates.
A highlight I want to talk about is the importance of SSL and how you get one for free by signing up with MilesWeb.
Make sure you read through the article as we have an exclusive 20% discount for One Page Love readers!
Should I get an SSL certificate for my website?
The short answer is yes. Back in 2014, Google announced that they added a slightly higher ranking “weight” to sites with SSL opposed to ones without. As soon as I read this, I setup an SSL on the One Page Love website.
So getting an SSL free with MilesWeb is a great move for your business.
SSL certificates enable you to secure the connection between your website and your website visitor’s browser. As a result of this, the important information transmitted through credit card / debit card is secured. SSL certificates are an important attribute for a website that deals with critical customer data.
In today’s world, customer trust is directly related to sales conversions; therefore having an SSL certificate is a crucial aspect specifically for the online business owners and also for many other business websites.
MilesWeb provides SSL certificates that work well with all the prominent browsers and devices and they protect unlimited number of servers.
With MilesWeb you can host your server in India
If your business or target market is based in India, you should strongly consider hosting your websites in India. MilesWeb offers better infrastructure, uptime and faster website loading within India.
Learn more about the benefits of hosting in India with MilesWeb. Here are your MilesWeb hosting package options:
Did you know you can secure a .in domain for only Rs 225 INR with MilesWeb?
Yes, and all other extensions too. If you are targeting the Indian community you can also host your servers in India for the fastest load time. MilesWeb servers are in India, UK, US and Romania – so you can choose to host elsewhere if needed.
What are the other benefits that MilesWeb offers?
MilesWeb is well established and have over 8000 Facebook fans of their brand.
Web hosting services offered by MilesWeb comprises of technology, uptime and 24x7x365 exclusive customer support. We have product and service offerings from basic hosting account to complex dedicated server clusters on multiple platforms.
- Unlimited SSD Storage & Bandwidth – zero storage and bandwidth restrictions on their standard Web Hostage package.
- Email Accounts – Unlimited POP3 / IMAP email accounts with Webmail to access emails anywhere, anytime. Includes email spam protection.
- cPanel Control Panel & Softaculous – Manage all aspects of your hosting account through an easy to use control panel interface.
- Free 1-Click Installs – Install WordPress, Joomla, Magento & lot many apps instantly through Softaculous within cPanel.
- 99.95% Uptime Guarantee – Their top-most priority is the availability of your website. You can trust them as they guarantee 99.95% uptime.
- Distributed and local servers – Their servers are based in India, UK, US and Romania
- Automatic Daily Backups – Have peace of mind knowing your content is backed up in case of any errors in your code.
- Instant Account Setup – Go online within minutes! Hosting accounts are setup instantly upon payment confirmation.
100% Money Back Guarantee and Award Winning Service
Last, but not least, they offer an Anytime Money Back Guarantee – so trying MilesWeb out is risk free. And best of all – they provide 24x7x365 Support via live chat, email and phone. They are rated 9.8/10 according to HostAdvice.com and received an award.
“MilesWeb.com were absolutely fantastic. Affordable and great at communicating and letting me know exactly what was happening. They offered great follow up support and were always extremely friendly and helpful. I needed fast, safe and secure dedicated server transfer and SSL installation. Both these tasks were carried out in superb time with extreme care and consideration for my users. I’ve worked with dozens of developers and teams. MilesWeb are thoroughly recommended!” – Ed Johnson, SuitLink Ltd
20% Discount exclusively to One Page Love readers!
Use the discount coupon code ONEPAGELOVE on check-out on all shared and reseller hosting plans to receive the discount.
Thanks again MilesWeb for supporting One Page Love by Sponsoring a post this week. It really helps keep our site updated regularity.
Visit MilesWeb.
by Rob Hope via One Page Love
Make Easy Graphs and Charts on Rails with Chartkick
We work with data presented in the various formats every day. From my point of view, one of the most convenient formats for presenting numerical data is a graph. Users like graphs, especially interactive ones, because they are beautiful and fun – in contrast to dull static tables. There are many solutions to render beautiful […]
Continue reading %Make Easy Graphs and Charts on Rails with Chartkick%
by Ilya Bodrov-Krukowski via SitePoint
Jess Tan
by Rob Hope via One Page Love
12 Creative Ways to Use Facebook Cover Images for Business
Do you want to do more with your Facebook cover image? Wondering how other businesses are using Facebook cover images? Your cover image is the perfect space to tell visitors more about your brand or products or drive home a call to action. In this article, you’ll discover 12 creative ways to use your Facebook [...]
This post 12 Creative Ways to Use Facebook Cover Images for Business first appeared on .
- Your Guide to the Social Media Jungle
by Neil Patel via
stinkdigital.com
by via Awwwards - Sites of the day