Contextual binding in laravel and how to make your code meet O in SOLID principles

Sometimes, we meet these kind of use cases or features when doing web application programming: 1 - multiple type of report to generate 2- multiple type of discount to handle 3- multiple type of payment to handle I recently faced with this use case when doing a freelance project for my customer. The requirement for this use case is that we have 2 types of reporting: human resources reporting and accounting reporting....

April 29, 2016 · 4 min · longka

Join with multiple condition in eloquent

Sometimes, you want to use join or left join or right join, etc … in eloquent, here is one example $orders = $this->order ->select(['orders.*']) ->join('customers', 'customers.id', '=', 'orders.customer_id') ->leftJoin('logs', function($join) { $join->on('orders.id', '=', 'logs.entity_id'); $join->where('logs.name', '=', EventsLog::EVENT_EMAIL_SENT_ORDER_PAYMENT_REMINDER); $join->where('logs.entity_type', '=', 'order'); }) ->where('orders.status', Order::STATUS_CREATED) ->where('orders.created_at', '<=', Carbon::now()->subDay($days)) ->whereNull('logs.entity_id') ->get(); return $orders; This will be same as raw sql query (postgres): select orders.id, customers.firstname, customers.lastname, logs.entity_id from orders join customers on (orders....

April 1, 2016 · 1 min · longka

Vọc vạch View trong laravel

Bài này dịch từ bài này ;) Khi làm việc với laravel, chắc hẳn bạn dùng rất nhiều đoạn code này. Nó rất tiện lợi trong việc trả về một view sau khi controller thực thi các tác vụ liên quan đến business requirement. return view('a/b/c.d.e.f', ['param' => $value]); Tuy nhiên, nó làm việc thế nào, hơi bị ảo đúng không nhỉ? Cùng đào sâu tìm hiểu thử xem thế nào?...

February 2, 2016 · 4 min · longka

Deeper look into laravel view helper function

When working with laravel, you may use this line of code pretty much. Its really helpfull to return a view after calling those business stuff inside a controller. return view('a/b/c.d.e.f', ['param' => $value]); However, have you ever ask yourself that how does it work ? Well, you can check with Laravel document about view here https://laravel.com/docs/master/views But, I think it’s not adequate. How that line of code actually works ?...

February 2, 2016 · 3 min · longka

Laravel 5 BindingResolutionException in Container.php line 827

Error: [caption id=“attachment_248” align=“aligncenter” width=“300”] laravel-ioc-binding-exception[/caption] Context that caused this eror [caption id=“attachment_249” align=“aligncenter” width=“300”] test controller[/caption] [caption id=“attachment_250” align=“aligncenter” width=“300”] foo service with php primitive type[/caption] When working with laravel 5, have you ever ask yourself that how** Laravel IOC** work, how **Laravel IOC** can handle concrete class binding instead of defining in somewhere (for laravel in Service providers). Basically, if you inject a concrete class to another class, it will automatically bind to that class by laravel Container...

January 18, 2016 · 2 min · longka

A diagram to implement realtime server (pubsub model)

A diagram to implement realtime server (pubsub model) [caption id=“attachment_190” align=“aligncenter” width=“300”]realtime app (pubsub model)[/caption] @todo: add more description, demo code...

November 30, 2015 · 1 min · longka