I'm trying to follow this: Find or Create with Eloquent
and the findOrCreate public function would work perfectly, but even tho I have "getRouteKeyName()" right above the findOrCreate, using Tag::find() will look for the given data as an ID, not as the name.
Should I make a completely new and custom PHP file with a function called findOrCreate, or there's a way I can tell this function to look-up by name and not by id?
public function getRouteKeyName()
{
return 'name';
}
public static function findOrCreate(array $tags){ <---- contains strings "default", "example", "other"
return Tag::find($tags[0]); <---- this only accepts IDs, but $tags[0] points to "default", not an ID. Obviously, it should look up the database via the name.
}
Am I missing something?
My Answer:
specific criteria you are looking for?
You can use a database query language such as SQL to search for data based on specific criteria. For example, if you are looking for all customers who have made a purchase in the last month, you could write a query like:
SELECT * FROM customers
WHERE purchase_date >= DATEADD(month, -1, GETDATE())
This query would return all customers who have made a purchase in the last month. You can customize the query to search for any specific criteria you are looking for.
Rate this post
4 of 5 based on 7752 votesComments