SOFTonSOFA

Page 2 of 3

array_merge vs array_replace vs + (plus aka union) in PHP

join

If you wrote some PHP, most likely you have used array_merge here and there for your arrays. You may have met array_replace function, introduced in PHP5.3. Finally, you could notice + operator (aka union).

Since all 3 do similar thing, and the docs don’t quite describe the difference between them, here’s a nice image of it

Continue reading

Revisionable – a quick example

A short reminder about my revisionable package (compatible with L4 & L5+) and quick example of how you can use it:

Zgłoszenia

Continue reading

Laravel Searchable – the best package for eloquent

search

In this first post of a series about https://github.com/jarektkaczyk/eloquence – the package that allows working with eloquent models in even simpler manner – I’m going to introduce you to the searchable feature of the builder class.

Continue reading

Laravel – Custom pivot model in Eloquent

pivot

Sometimes you may wish to use custom pivot model when working with many-to-many relationships in Eloquent, in order to add some behaviour on top of the core features.

There are a few things to consider before you start.

Continue reading

Laravel – querying any level far relations with simple trick

trick

Eloquent provides one Relation type for far related tables – hasManyThrough. However it works only with with cascade of hasOne/hasMany relations and you can use it only for 2 levels of nesting, while sometimes you need more.

Imagine, that you want to get the posts for logged-in user, having this setup:

Now, because there is no built-in method for such case, you would probably think of getting all the tags, looping through them, and merging all the posts from each tag. While this would work, it would be cumbersome, so let’s make it easier!

Continue reading

Eloquence emerging

eloquence-emerging

After spending long time with Eloquent I finally decided to release some of my work – extensions that will make your life easier, when working with Eloquent ORM.

They will be released bit by bit on github and much more will be found in the book I’m working on.

https://leanpub.com/eloquence-emerging

As a starter take a look at the repo and make sure to follow, for I will be updating it regularly!

https://github.com/jarektkaczyk/eloquence

 

Leave your thoughts in the comments – what would you like me to cover in the book, what is the most difficult part that you need help with, what use-cases would be most desirable.

Laravel 5 Eloquent Global Scope how-to

scope

If you are looking for an example of Eloquent Global Scope feature, then you’re in the right place!

Check the ready-to-use demo at …

Continue reading

Laravel Query Builder global scope – how to use custom Connection and Query Builder in Laravel 4

builder

Eloquent Global Scopes make it easy to customize your Model’s queries, however sometimes it is just not enough.

You may want to use similar solution for you DB::table(..) calls as well. While there’s no built-in feature for this, you can still do it with just a little more effort, and here’s how it’s done.

Continue reading

sofa/revisionable – nice & easy way to keep track of db changes

revisions

It is essential for every application to keep track of the data revisions. As an admin or sort of supervising user, you want to know how, when and who is responsible for changing the data.

Here’s something you should try out, because it makes this kind of work stupid-simple:

Sofa/Revisionable

Continue reading

Tweaking Eloquent relations – how to get hasMany relation count efficiently?

count

When working with relationships, most likely you need to get count of related models in many places. There are obvious ways to achieve this of course, but not always efficient. Especially when you are loading a collection of models and their relations.

So let me show you what we can do about it!

Continue reading

« Older posts Newer posts »

Copyright © 2017 SOFTonSOFA

Theme by Anders NorenUp ↑