mardi 31 janvier 2017

Querying a belongsTo relationship

I have two tables, "tasks" and "courses". There is a one to many relationship setup (tasks belongTo a course, courses hasMany tasks). I am trying to filter my list of tasks, but am confused as to how to query based on a column in the courses table.

In the courses table I have a column called "college_name". I have a dropdown filter, and when I select a college name from that, I want to return all tasks that are linked to rows in the courses table that has the same 'college_name'.

So the query I am trying to build is something along the lines of "select all the tasks that belong to a course with the college_name of X (college name is taken from dropdown select input. In my controller I am getting the dropdown value like this:

$college = Input::get('colleges_filter');

...which returns the college name (e.g. "Oxford College"). I now need to take that add use it in the query, but everything I try errors. Can anyone help please?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2jP8TOc
via IFTTT

Aucun commentaire:

Enregistrer un commentaire