twopiers

twopiers

Member Since 6 Years Ago

Experience Points
8,690
Total
Experience

1,310 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
124
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 2
8,690 XP
Sep
22
1 month ago
Activity icon

Replied to Eloquent Save Converting Unicode Characters

First, THANK YOU for taking time out of your day to help me. I love the Laravel community.

Just ran a couple of tests...

If I paste 'Bordeaux–Mérignac Airport' directly into the location field of my MySQL client (Table Plus on Mac), it saves just fine.

Here's the weird(er) part: I wanted to see if Eloquent was doing anything to the string to prep it prior to saving to MySQL, so I created a very simple web form to edit the SomeModel location field. When presented in the browser, the location field text input element contains the large space character (as expected). If I highlight that and then type an en dash character (option-dash on the Mac), then save, the en dash saves perfectly.

public function update(SomeModel $someModel, Request $request)
{
    $input = $request->validate([
        'location' => 'required|string|max:255'
    ]);

    $someModel->update($input);
}

So, I don't think it's a MySQL collation or charset issue, and I don't think it's an Eloquent issue.

Now I'm really stumped.

Activity icon

Replied to Eloquent Save Converting Unicode Characters

mysql settings in config/database.php

'mysql' => [
    'driver' => 'mysql',
    'url' => env('DATABASE_URL'),
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'unix_socket' => env('DB_SOCKET', ''),
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
    'prefix_indexes' => true,
    'strict' => true,
    'engine' => null,
    'options' => extension_loaded('pdo_mysql') ? array_filter([
        PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
    ]) : [],
],
Activity icon

Replied to Eloquent Save Converting Unicode Characters

Thank you for the suggestion. I changed the field type to text and tried it again. Same result. Bummer.

Activity icon

Replied to Eloquent Save Converting Unicode Characters

Yeah, should've posted that. Sorry.

location is a varchar field. Its collation is 'utf8mb4_unicode_ci' and its charset is 'utf8mb4'.

Activity icon

Started a new Conversation Eloquent Save Converting Unicode Characters

I have an app that pulls some information from an API and simply saves it (via an Eloquent model) to MySQL. I'm running into an issue when a string from the API contains an en dash character. Somewhere along the way (I don't know if this is an Eloquent or PHP or MySQL thing), the en dash character gets converted to something else.

Some code:

//lookup value via API and store in $response
//for this example, $response['location'] = 'Bordeaux–Mérignac Airport'
//the hyphen is an en dash character
$location = $response['location'];

dd($location); // 'Bordeaux–Mérignac Airport'

So far, the en dash is just fine. If I copy/paste this value into a unicode converter tool (like this one), it says the en dash character's hex value is

– 

which is correct (I think). Then I save:

$some_record = App\SomeModel::find(22); //grab my model
$some_record->location = $location;
$some_record->save();

dd($some_record->location); // 'Bordeaux–Mérignac Airport'

Now the en dash is gone, replaced with a large space character. If I copy/paste the value into a unicode converter tool and convert it, it says the character is now

– 

which is something called a START OF GUARDED AREA character.

The MySQL table's charset is set to 'utf8mb4' and the collation is set to 'utf8mb4_unicode_ci'.

I'm clearly doing something wrong or forgetting a step somewhere. I'm at the end of my knowledge gap on this. Any advice would be most welcome.

Thanks for listening.