Vadoo Splash Screen
repeat

Illuminate [DB] vs Eloquent [Model]

 
Vadoo MySQL PHP

In many cases using a Model is a great idea and in some traditional platforms or frameworks this was a requirement. However, in Laravel, you have a choice because it has two options a) Illuminate [sugar over SQL] b) Eloquent.

Some would argue and the author here would be one, that Laravel's Illuminate with its DB:: class has already created the Model for you and `sort of` does away with this extra layer. Below is an example piece of relatively complex code for an API:


        $orderProducts = DB::table('orders-products')
        	->join('products', 'products.id', '=', 'orders-products.product_id')
        	->join('orders', 'orders.id', '=', 'orders-products.order_id')

		->join('customer-eav', function($join) {
			$join->on('customer-eav.customer_id', '=', 'orders.customer_id');
			$join->on('customer-eav.customer_attribute_key', '=', 'orders-products.customer_ship_to_postcode_key');
		})

        	->where('orders-products.order_id', '=', $order_id )
        	->select('orders-products.*', 'products.name as product_name', 'customer-eav.value as ship_to_postcode')
        	->get();

	

This is all rather explicit, clean and to the author's /dev eye quite clear. It is also simple enough to debug or update? This example is taken from `vShop` and there are more complex ones, but the above hopefully illustrates or `illuminates` the point that this `query` is creating a data-model [yes IN THE CONTROLLER] but with not much more code than its sister Eloquent.

It also has the plus that it is modular, hard to break and also quick if that is an API requirement [especially true with DB joins]. My only point is that many Digital Agencies insist on Eloquent and it is fine in some circumstances, but many Laravel /devs use the above very well with RAPID development and moreover easy-to-understand code.

Clients want working and easy to follow systems, not over-engineered solutions and while Eloquent is an excellent product for very [very] complex systems [and basic CRUD], I am yet to find one where Illuminate fails or doesn't shine. The Laravel people use Illuminate in their primary docs, so it wasn't created for fun = just saying.

The author is a big fan of EAV having worked with many large eCommerce systems over the years and ORM + EAV can be a hard nut to crack or more specifically `make it clear` to a new /dev. Illuminate does the job [very well] and does what it says on the tin. That's important.