cservices
5 months ago

Returning string data from a relationship only

Posted 5 months ago by cservices

I have two tables.

  1. Types - Contains three fields: id, name and path
  2. Extensions - Among the fields is one named type_id - relates to the entry in Types

I first need to know the extension in order to get the path for the type. So I have a line of code in my method that looks like this:

// Get path
$ext = Extension::where('extension', $extension)->with('hasType')->first();
$path = $ext->hasType->path;

All I need is the path string. Is there a way to make a query using this relationship, but return only the path string of data I am seeking?

Looking to see what all I can do with these relationships.

Or do I need to create a separate method that does this for me, then return the string back to the method that needs it?

Please sign in or create an account to participate in this conversation.