Hi guys,
OK so this probably isn't the biggest problem in the world and I'm sure someone will be able to help me out with where I'm going wrong. Here's a few facts before I get to my problem:
- Laravel 5 & mysql
- I have 3 main tables:
meetups, events and locations
- I also one pivot table:
event_location
- Meetups
hasMany Events
- Events
belongsTo Meetups
- Events
belongsToMany Locations
- Locations
belongsToMany Events
The problem
I'm currently trying to search the locations (via a form – i.e. `Input::get('data), and this would bring up all events that have that location, and all meetups that associate with that event.
Within my SearchController, I have the following:
// Get the searched data
$data = Input::get('data');
// Get all location, which are 'LIKE' the inputted data.
$locations = Location::where('title', 'LIKE', '%'. $data .'%')->get();
At this point I'm not sure how to proceed. I need to access the events from each location and after that I'd need a get the meetup that corresponds with that location, but I'm not sure how to go about this. Can this be done with joins() or would I loop through the $locations variable and get the ->events for each of those and put them into an array? Or, should I be using DB:: and running a custom query?
Hope someone can help me, thanks in advanced!
Luke