title: Laravel - Select only specified columns in joined tables
body: <p>Here's my situation I have joined tables but the problem is some of those columns have the same name from other tables. What I want to know is how I can prevent this from happening. The columns that have the same name are <code>created_at</code> but I only want to use methods' table created_at (<code>methods.created_at</code>). Here is my code to explain my situation better</p>
  
  <pre><code> $filtered_table = Method::leftJoin('users', 'users.id', '=', 'methods.created_by')
        -&gt;leftJoin('roles', 'roles.id', '=', 'users.role_id')
        -&gt;leftJoin('types', 'types.id', '=', 'methods.type_id')
        -&gt;where($request-&gt;filters)//will act as a searchmap
        -&gt;get([ 'users.username', 'users.id AS users_id', 'methods.*', 'methods.id AS method_id', 'methods.name AS method_name', 'roles.id AS role_id', 'roles.name AS role_name',
        'types.id AS type_id_typetable', 'types.name AS type_name']);
  </code></pre>
  
  <p>notice how <code>-&gt;where</code> is an array of objects, I am using it as a searchmap for the clause. But my problem is like what I said above that the tables has the same name on some columns like for example created_at, the other columns doesn't matter since I am not using it.</p>
  
  <p><strong>The question is how do I explicitly tell the query that I am using the <code>methods.created_at</code> when I am searching it through the searchmap (In this case, <code>$request-&gt;filters['created_at']</code>.</strong> Please, let me know if you need any more details.</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>if($("#date_select_off").val() == "daily") {
          let day = $("#day_date").val();
          filter_list.created_at = day;
        }
  </code></pre>
  
  <p>in this code in jquery I am naming the key the same as the column so that I can use it as parameter in the php query. But my like my initial problem I simply can't name it <code>filter_list.methods.created_at</code> any help with this is greatly appreciated.</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p><a href="https://i.stack.imgur.com/Jxwyk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jxwyk.jpg" alt="enter image description here"></a></p>
  
  <p>How would I use a 'LIKE' query to that particular key value pair?</p>
  
  <pre><code>-&gt;where($request-&gt;filters)//will act as a searchmap
        -&gt;orWhere('methods.created_at', 'LIKE', $request-&gt;filters['methods.created_at'])
  </code></pre>
  
  <p>I tried doing this but it is just wrong since the key value pair is already hitting on the first where clause.</p>
  
  <p><strong>EDIT 3</strong>
  It could use some improvements but yeah</p>
  
  <pre><code>  $filtered_table = Method::leftJoin('users', 'users.id', '=', 'methods.created_by')
        -&gt;leftJoin('roles', 'roles.id', '=', 'users.role_id')
        -&gt;leftJoin('types', 'types.id', '=', 'methods.type_id')
        -&gt;where($request-&gt;filters)//will act as a searchmap
        -&gt;orWhere('methods.created_at', 'LIKE', '%' . $request-&gt;filters['methods.created_at'] . '%')
        -&gt;get([ 'users.username', 'users.id AS users_id', 'methods.id AS method_id', 'methods.name AS method_name', 'methods.created_at AS method_created_at', 'roles.id AS role_id', 'roles.name AS role_name',
        'types.id AS type_id_typetable', 'types.name AS type_name']);
  </code></pre>