The difference in the casing of the column name "resourceId" between the RAW query and the Eloquent query is due to the way Laravel handles column aliases.
In the RAW query, the column alias is not recognized by Laravel, so it returns the column name in lowercase. This is the default behavior of the database when no alias is provided.
In the Eloquent query, Laravel recognizes the column alias and converts it to camelCase by default. This is a feature of Laravel's Eloquent ORM.
If you want to achieve consistent casing for column aliases in both RAW and Eloquent queries, you can use the DB::connection()->raw() method to specify the column alias explicitly in the RAW query. Here's an example:
$raw = DB::raw("SELECT
periods.id,
event_id AS resourceId
FROM
periods
JOIN events ON periods.event_id = events.id AS resourceId");
$raw = collect(DB::select($raw));
dd($raw);
By providing the column alias explicitly in the RAW query, Laravel will return the column name with the specified casing.
Alternatively, if you want to change the casing of the column alias in the Eloquent query, you can use the selectRaw() method instead of get() and specify the column alias with the desired casing. Here's an example:
$periods = Period::whereIn('event_id', $events_id)
->join('events', 'periods.event_id', '=', 'events.id')
->selectRaw('periods.id, user_id AS resourceId')
->get();
dd($periods);
By using selectRaw(), you can specify the column alias with the desired casing, and Laravel will return the column name accordingly.