Categories
Slim Framework

Creating a RESTful API with Slim Framework 3 and Eloquent

Slim is a full-featured, open-source PHP micro framework that helps you quickly write simple yet powerful web applications and APIs. It comes with a sophisticated URL dispatcher and middleware architecture that makes it ideal for static websites or API prototyping. It supports all(GET, POST, PUT, DELETE) the HTTP methods. This article examines Slim in detail, […]

Categories
Slim Framework

How to Use Eloquent in Slim Framework

The Eloquent ORM makes it incredibly easy to interact with a database. Today we’ll look at how we can use Eloquent to interact with our database inside your Slim Framework. The Eloquent ORM provides an ActiveRecord implementation to work with your database. This means that each model you create corresponds to a table in your […]

Categories
Laravel

Laravel 5.5 – How to log all Eloquent Queries

In this post, I will show you simple method to log each and every Eloquent Query of your application executes. We gonna log queries to the storage/logs/laravel.log file. To log database queries we gonna add a database calls lister as shown in the below example. Open your app/Providers/AppServiceProvider.php and add following code to boot() method: […]

Categories
Laravel

Polymorphic Eloquent Relationships in Laravel 5

In this post, I would like to show you creating polymorphic relationships in the Laravel5 application. Probable polymorphic relationships are the most advanced eloquent relationships in all available joins in Laravel. Polymorphic relationships are extremely useful to share same data structure(table) between two or more different types(tables). For Example, let’s assume, we have different types […]

Categories
Laravel

Laravel eloquent complex queries on relationships

Very Laravel developer should know this little trick, using this trick you can define complex conditions on the eloquent relationships. This method chaining helps you to add custom where/filter conditions for relation columns. Sometimes the simple belongsTo() and hasOne() functions can not quite manifest the complex relationship function you did like to use. Fortunately , […]

Categories
Laravel

Laravel 5 Eloquent – Attribute casting

One of the Laravel 5 awesome feature is Attribute casting. Casting attribute means changing the attribute values to a particular type. for example Boolean, integer, strings. Eloquent models allows you to change datatype of the Attribute values automatically with Attribute casting feature.To cast a attribute of the model ,all you have to do is just […]

Categories
Laravel

Laravel 5 Eloquent lazy eager loading

Sometimes you may need to eager load a relationship after the parent modal has already been retrieved. For Example this may be very useful if you need to dynamically decide whether to load related models or not, or in combination with caching. You can also set additional query constraints on the eager loading query, by […]