The issue you're experiencing is due to the chaining of methods in your query. When you call first() on your query builder, it returns the first result as an instance of the model. However, when you chain value('long_name') onto it, it actually creates a new query to retrieve the value of the specified column from the first record in the table, regardless of any previous conditions.
To solve this, you can modify your query to retrieve only the specific column using the pluck() method. Here's an example:
$countryName = Countries::where('short_name', '=', 'US')->pluck('long_name')->first();
This will retrieve the value of the long_name column for the first record that matches the condition 'short_name' = 'US'.
Alternatively, if you want to retrieve the entire record as an array, you can use the toArray() method on the model instance returned by first(). Here's an example:
$country = Countries::where('short_name', '=', 'US')->first()->toArray();
This will give you an array representation of the first record that matches the condition 'short_name' = 'US'.
I hope this helps! Let me know if you have any further questions.