That's a good question. Unfortunately, from the actual method below, it doesn't seem to be possible with using the framework's standard firstOrCreate method. In my opinion, this is desired behavior, but I can see where there would be times where case sensitive version would be useful.
/**
* Get the first record matching the attributes or create it.
*
* @param array $attributes
* @param array $values
* @return \Illuminate\Database\Eloquent\Model|static
*/
public function firstOrCreate(array $attributes, array $values = [])
{
if (! is_null($instance = $this->where($attributes)->first())) {
return $instance;
}
return tap($this->newModelInstance($attributes + $values), function ($instance) {
$instance->save();
});
}
Because the where clause is translated to an sql clause of something like SELECT * FROMtableWHEREValue= "input", it should be case insensitive as that is typically the default, at least for MySQL.
EDIT
And I am just seeing now that I wrote:
but I can see where there would be times where case insensitive version would be useful