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

Một vài lưu ý khi cài đặt php7 (php-fpm) từ source code trên linux (fedora)

Giả sử bạn muốn cài đặt trên fedora, php7, php-fpm với nginx là proxy hứng request đẩy qua cho php xử lý (thông qua php-fpm). Khi cài đặt từ source code có thể bạn sẽ gặp những vấn đề sau: Thiếu các thư viện khi chạy lệnh ./congigure Chỉ định đường dẫn đến thư mục sẽ cài php mà bạn muốn( hữu ích khi bạn muốn cài nhiều phiên bản php trên môi trường làm việc của bạn)....

March 1, 2016 · 2 min · longka

Release optivo mail client for laravel

Optivo is quite big mail service provider in Germany https://www.optivo.com/en. This is one of optivo mail client for laravel (use Optivo HTTP API) https://github.com/nguyentienlong/laravel-optivo https://packagist.org/packages/longka/laravel-optivo Todo: write an article about how to create your own laravel package like this package...

February 28, 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