Laravel 5 Collection – Use multiple filters in your collection

Right now I am working on a project with Laravel 5.1. I’ve a situation here where I need to fetch all receipts from databased based on Start and End time of Breakfast, Lunch and Dinner. I could easily do it by three separate query to database and stored them in three variables but here I can reduct the hit to database server and use the collection functions.

I’ve first fetch all the receipts of a given date

$receipts	= Receipts::where(function($query) use ($report_date){
 
		$query->where(function($query) use ($report_date){
			     $query->where('date', '=', $report_date);
			});
		$query->where(function($query){
			$query->where('type', '=', 'restaurant');
				$query->orWhere('type', '=', 'takeaway');
			});
		})
		->orderBy('create_date')
		->get();

Now I have all receipts of a single day but I want to slice the receipts for breakfast, lunch and dinner receipts with the help of Laravel collection. I didn’t know how to use multiple filters in a single collection and founding nothing after searching google and stackoverflow. Then I started using common sense and it worked like a charm.

Multiple Filter in a single Collection Object

Here I need to give breakfast_start and breakfast_end time and it will filter with create_date property of the object. Anything in between, it will return the breakfast receipts .

$breakfast = $receipts->filter(function($item) use($breakfast_start){
		    return $item->create_date >= $breakfast_start;
	        })
		->filter(function($item) use($breakfast_end){
		    return $item->create_date <= $breakfast_end;
	    });

The code worked perfectly and I though I should share the code snippet which might be helpful for someone like me.

DevSpace – Ubuntu 14.04 Vagrant Box for LAMP stack development environment

DevSpace Vagrant is a simple Ubuntu Trusty64 vagrant configuration for LAMP stack developers which also includes many related modern development tools.

Ubuntu 14.04 Vagrant Box – DevSpace

This vagrant use ubuntu/trusty64 from Atlas Vagrant Box. On your ‘vagrant up’ command, this vagrantfile will automatically download the box. Vagrant folder here contain a bootstrap.sh file which provision the vagrant box.

You need to place your projects in projects directory. This directory is synced with /var/www/htmldirectory in the virtual machine. This project folder also contain a config folder which is used during the provisioning.

This vagrant box is configured to use ‘1024mb’ of RAM and 1 Cpu. You can change ths configuration from Vagrantfile.

DevSpace Vagrant Installation

Install via Git

To use DevSpace vagrant, clone this github repo

$ git clone https://github.com/arifulhb/devspace.git

to your mac/pc/linux. When clone is complete, go to the `devspace` and now you are ready to use your Virtual Machine.

Use

Start the VM

$ cd /devspace
$ vagrant up

First time of your ‘vagrant up’ will provision the vagrant. You can see the status of your VM from http://192.168.33.10. You can check the `phpinfo` from http://192.168.33.10/phpinfo.php

List of Packages in DevSpace Vagrant

  • Apache2
  • PHP 5.6.7
  • MySQL 5.5.41
  • Git 1.9
  • Composer
  • Nodejs
  • NPM
  • Bower
  • Gulp

Requirements

You must have Vagrant and VirtualBox installed in your pc.

Default Credentials

These are credentials setup by default.

Host Address: – Hose: 192.168.33.10 (Change in Vagrantfile if you like)

SSH: vagrant / vagrant

MySQL: root/root
– Host: localhost
– Port: 3306

Fork and Tweet

This project is shared as Github Rep. If you find it helpful, you can Star and Fork in github. You can also help me to grow this project by tweet this.

How to remove controller name from URL in CodeIgniter

In CodeIgniter or any MVC application, the regular URL structure is like example.com/controller/function/parameter which appear as example.com/user/profile/ariful.  But sometimes we may want to omit the controller name here to make the url more beautiful like example.com/profile/ariful or even example.com/ariful as best url.

This beautiful url can be achieve through the URI Routing of CodIgniter. In
For example.com/ariful, use this code

 application/config/route.php

application/config/route.php file, you’ve to write following code for example.com/profile/ariful

  $route['user/(:any)']             = "user/profile/$1";

For example.com/ariful, use this code

  $route['(:any)']                  = "user/profile/$1";

If you have multiple parameters like

public function profile($username, $city)
{
     echo "You are ".$username." from ".$city;
}

Your route will be

5
  $route['(:any)/(:any)']                  = "user/profile/$1/$2";

If you want to use number in parameter instead of string like these examples, you need to use (:num) instead of (:any).

If you are looking for something like modifying URL, I hope this post may help you. If you’ve any further question, you can comment bellow.

Collection of My Web Development Assets

This is a short story of why I initiated the GitHub repo  “Frameworks Library Plugins I use in work”

I am developing web sites and web applications from 2011. Though I was working as a programmer for long time, I drive into web technologies after staring freelancing and outsourcing through oDesk.

My evolution is something like WordPress > CodeIgniter > Laravel > AngularJs > Nodejs. I started my outsourcing career with small WordPress thick and Installation, Theme modification and ended with WordPress theme development. Then eventually moved to Web Application development using CodeIgniter, Laravel and Angularjs. Though these are only the lading Frameworks, I used many other library, plugins, scripts etc. But most of time I keep forgetting which library or plugin or script I used in last projects and needed to research those. I considered this as a time killing process.

To solve this issue, I though to initiate and maintain a list of Frameworks, Library, Plugin, Scripts I used. It will be easy for me to track my usages and might be helpful for others too. So I initiated GitHub repo named “Frameworks Library Plugins I use in work”.  This is not I’ve listed all things I used in past years, of-course I’ve forgot many of them but I am intended to keep it filling.

If you like the repo, you can fork it and continue as your repo as well.

Philosophy of Important Things To Do

I’ve been a stargazer from my childhood. In any quite place with dark night and multi billions of stars in sky is the all best moments I’ve ever passed in my life.

My wife found this photo in 9Gag and shared in my facebook wall. The quote means a lot to me and though to share in my blog to keep it close to me.

“If people looked at the stars each night, they’d  live a lot differently – when you look into infinity, you realize that there are more important things than what people do all day.”

philosophy of important things to do
Source: 9gag

Some people look before they cross the road

Found this random quote in Facebook and fill to preserve it to keep me motivating toward the science and prosperity and keep me away from superstation.

“I have noticed even people who claim everything is predestined, and that we can do nothing to change it, look before they cross the road.” – Stephen Hawking

stephen hawking quote
Disclaimer: I didn’t search for any direct reference for this quote, but I like the saying even if this is not said by Stephen Hawking

Cats In Malaysia

If you are in First time in Malaysia, you’ll see a very common phenomena here and this is Cat. Malaysian people loves cat very very much and its part of their daily life.

Usually you’ll find cat in everywhere. In house,  car, hotels, restaurants, roads etc etc. Well the cats are very friendly and adorable and sometime you’ll find even more exciting even if you don’t like cat (like me).

I found this cats in Tioman Island. When I was returning to my room after a beach walk, I found four (I guess brothers) of them was sleeping in a table. I found it soo funny and intimate  moment and I couldn’t stop myself to document the moment.

Sleeping Cats in Tioman Island
Sleeping Cats in Tioman Island
Sleeping Cats in Tioman Island
Sleeping Cats in Tioman Island
Sleeping Cats in Tioman Island
Sleeping Cats in Tioman Island

 

Also my wife didn’t miss the chance to take a photo with them :)

Tajia Sleeping Cats
Tajia Sleeping Cats

Jonker Street Night Market in Malacca

Jonker Street

Malacca is the Historic State of Malaysia and Jonker Street was most known for Antique Shops which is mostly replaced by modern clothing shops and restaurants.

Jonker Street
Jonker Street
Jonker Street
Jonker Street
Jonker Street
Jonker Street

In my experience and peoples review, Jonker street get its life back at every night and stay sleep at day time. You’ll know it when you’ll experience the rush, music and joy in the Night Market.

Night Market of Jonker Street

Jonker Street Night Market Gate
Jonker Street Night Market Gate
Jonker Street Night Market
Jonker Street Night Market
Shop at Jonker Street Night Market
Shop at Jonker Street Night Market

 

Souvenir of Malacca
Souvenir of Malacca
People walking at Night Market
People walking at Night Market

Night Market is full of Music and shows. You’ll see many street musicians doing music or someone showing magic or any street show. At the other side of the market, there is always some stage show going on. Most of time they’ll sing local songs but I bet you gonna love them.

Street Musician at Night Market
Street Musician at Night Market
Stage show at other side of Night market
Stage show at other side of Night market

 

Butterfly Garden of Cameron Highlands

Butterfly Garden

Alongside with all Agro-firms and gardens in Cameron Highlands, there are two Insect firms also. One of them is Butterfly Garden and another one is Butterfly Farm. Both are almost same  in looks and purpose. We visited the Butterfly Garden and here are some photos.

Butterfly in the Garden
Butterfly in the Garden

Truly saying.. I was a little bit disappointed by the number of variety of Butterfly there. I was expecting something more. I asked an assistant there about why so small amount of butterfly is there, he replied that there was a planned shipment suppose to bring more butterfly that morning, but they didn’t supply at that day. Thats why we saw very few on that day. Maybe it was our bad luck that day.

Butterfly in the Garden
Butterfly in the Garden
You can take photos with Butterfly
You can take photos with Butterfly

Insects in Butterfly Garden

As the Rose Garden has many other types of flowers, Butterfly Garden has many other types of insects also and here they are..

Stick Insect in Butterfly Garden
Stick Insect in Butterfly Garden
Leaf Insect in Butterfly Garden
Leaf Insect in Butterfly Garden
Giant Grasshopper in Butterfly Garden
Giant Grasshopper in Butterfly Garden
Baby Caterpillar
Baby Caterpillar
Scorpion also...
Scorpion also…
Giant Beetles
Giant Beetles

 

Lizard Snakes in Butterfly Garden

There are two sections for Lizard and Snakes and here they are posing for me 😀

Lizard in Butterfly Garden
Lizard in Butterfly Garden
Lizard in Butterfly Garden
Lizards

 

Shy snake
Shy snake
Snakes in Butterfly Garden
Snakes in Butterfly Garden
Snakes in Butterfly Garden
Snakes in Butterfly Garden

Cameron Highland Attraction – Rose Garden

Rose Garden of Cameron Highland

Rose Garden is one of the mind blowing attraction of Cameron Highland in Malaysia. The small size garden has thousands of categories of flowers and many installation to make you feel happy.

Cameron Highland is a place which Malaysia developed as Agro-Tourism spot. We  visited the lovely place with chilling weather. The place has many small to medium farms and gardens which deal with mostly Agro products. Rose Garden is one of them.

Rose Garden
Rose
Flowers of Rose Garden
Roses of Rose Garden
Roses in Rose Garden
Roses in Rose Garden

Narrow Passage of Rose Garden

Rose Garden is a very small farm and very narrow passage for walk but the beautiful flowers blew our minds to think anything else about except the beauty of flowers.

Narrow passage in Rose Garden
Narrow passage in Rose Garden
Tajia and My mother in Rose Garden
Tajia and My mother in Rose Garden

Is Rose Garden only have Roses?

We was very curious about Rose garden to know if the garden has only roses..? Though we’ve seen many many variety of Roses (Sorry I dont know name of each category), it wasn’t a garden of Roses only. There are many many types of flowers are there to make you wonder.

Flowers of Rose Garden
Flowers of Rose Garden
Flowers of Rose Garden
Flowers of Rose Garden
Flowers in Rose Garden
Flowers in Rose Garden
Flowers in Rose Garden
Flowers in Rose Garden

Sculpture and Installation in Rose Garden

There are few very nice Sculptures and Installation arts inside the Rose Garden which gives the garden more meaning.

Sculptures in Rose Garden
Sculptures in Rose Garden
Installation art in Rose Garden
Installation art in Rose Garden
Installation art in Rose Garden
Installation art in Rose Garden
Installation art in Rose Garden
Installation art in Rose Garden