connecteev

connecteev

Member Since 4 Years Ago

Experience Points
10,930
Total
Experience

4,070 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
90
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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 3
10,930 XP
Dec
31
3 weeks ago
Activity icon

Started a new Conversation Insert A NON-EMPTY Commit Before The Root Commit In Git?

I have a problem, please be kind enough to advise! I have an existing git repo, and for various reasons(that I wont go into here), I am trying to create a ROOT commit

Say this is my git commit history:

(HEAD) C5-C4-C3-C2-C1 (ROOT)

I want to add an initial commit (CX, which is not empty) BEFORE C1. So it should end up like this:

(HEAD) C5-C4-C3-C2-C1-CX (NEW ROOT)

I found a similar question here: https://stackoverflow.com/questions/645450/insert-a-commit-before-the-root-commit-in-git But it's for appending an EMPTY git commit before the existing root. I also tried the steps in the answer here: https://stackoverflow.com/a/9736098/11491070 with one change: I replaced git commit --allow-empty -m 'initial' with git add .; git commit -m "initial laravel commit"; git push; and then this rebase step: git rebase --onto newroot --root master is failing with a TON of merge conflicts:

First, rewinding head to replay your work on top of it...
Applying: add initial quickadminpanel, with admin intrface and APIs for tags. Also added (but not yet enabled) ajax datatables module
Using index info to reconstruct a base tree...
.git/rebase-apply/patch:4537: trailing whitespace.
     * 
.git/rebase-apply/patch:4539: trailing whitespace.
     * 
.git/rebase-apply/patch:4547: trailing whitespace.
     * 
warning: 3 lines add whitespace errors.
Falling back to patching base and 3-way merge...
CONFLICT (add/add): Merge conflict in webpack.mix.js
Auto-merging webpack.mix.js
CONFLICT (add/add): Merge conflict in routes/web.php
Auto-merging routes/web.php
CONFLICT (add/add): Merge conflict in routes/api.php
Auto-merging routes/api.php
CONFLICT (add/add): Merge conflict in resources/views/welcome.blade.php
Auto-merging resources/views/welcome.blade.php
CONFLICT (add/add): Merge conflict in resources/sass/app.scss
Auto-merging resources/sass/app.scss
CONFLICT (add/add): Merge conflict in resources/sass/_variables.scss
Auto-merging resources/sass/_variables.scss
CONFLICT (add/add): Merge conflict in resources/lang/en/validation.php
Auto-merging resources/lang/en/validation.php
CONFLICT (add/add): Merge conflict in resources/lang/en/passwords.php
Auto-merging resources/lang/en/passwords.php
CONFLICT (add/add): Merge conflict in resources/lang/en/pagination.php
Auto-merging resources/lang/en/pagination.php
CONFLICT (add/add): Merge conflict in resources/lang/en/auth.php
Auto-merging resources/lang/en/auth.php
CONFLICT (add/add): Merge conflict in resources/js/bootstrap.js
Auto-merging resources/js/bootstrap.js
CONFLICT (add/add): Merge conflict in resources/js/app.js
Auto-merging resources/js/app.js
CONFLICT (add/add): Merge conflict in package.json
Auto-merging package.json
CONFLICT (add/add): Merge conflict in database/seeds/DatabaseSeeder.php
Auto-merging database/seeds/DatabaseSeeder.php
CONFLICT (add/add): Merge conflict in database/migrations/2014_10_12_100000_create_password_resets_table.php
Auto-merging database/migrations/2014_10_12_100000_create_password_resets_table.php
CONFLICT (add/add): Merge conflict in database/factories/UserFactory.php
Auto-merging database/factories/UserFactory.php
CONFLICT (add/add): Merge conflict in database/.gitignore
Auto-merging database/.gitignore
CONFLICT (add/add): Merge conflict in config/services.php
Auto-merging config/services.php
CONFLICT (add/add): Merge conflict in config/logging.php
Auto-merging config/logging.php
CONFLICT (add/add): Merge conflict in config/database.php
Auto-merging config/database.php
CONFLICT (add/add): Merge conflict in config/cache.php
Auto-merging config/cache.php
CONFLICT (add/add): Merge conflict in config/broadcasting.php
Auto-merging config/broadcasting.php

How can I fix this problem? Please help!

Dec
28
3 weeks ago
Activity icon

Awarded Best Reply on How To Modify Laravel's Returned Paginated Data ?

@jlrdw thanks! So I guess the length aware aginator is for more fine grained control and manual pagination with DB facades.

Re: the original problem, here's how I fixed it in the end..for future reference. Blew an entire afternoon on this :( but at least it works now.

$getPostsApiResponseArr = $getPostsApiResponse->getData(true);
$postsArray = $getPostsApiResponseArr['data'];

// make changes to $postsArray

$getPostsApiResponseArr['data'] = $postsArray; // Need to preserve the rest of the (original) Laravel pagination data
$getPostsApiResponse->setData($getPostsApiResponseArr); // see https://laravel.com/api/5.3/Illuminate/Http/JsonResponse.html#method_setData
return $getPostsApiResponse;

Activity icon

Replied to How To Modify Laravel's Returned Paginated Data ?

@jlrdw thanks! So I guess the length aware aginator is for more fine grained control and manual pagination with DB facades.

Re: the original problem, here's how I fixed it in the end..for future reference. Blew an entire afternoon on this :( but at least it works now.

$getPostsApiResponseArr = $getPostsApiResponse->getData(true);
$postsArray = $getPostsApiResponseArr['data'];

// make changes to $postsArray

$getPostsApiResponseArr['data'] = $postsArray; // Need to preserve the rest of the (original) Laravel pagination data
$getPostsApiResponse->setData($getPostsApiResponseArr); // see https://laravel.com/api/5.3/Illuminate/Http/JsonResponse.html#method_setData
return $getPostsApiResponse;

Activity icon

Replied to How To Modify Laravel's Returned Paginated Data ?

@jlrdw thanks for chiming in!

See my comment above.

Btw, I saw your link and googled 'length aware paginator' for laravel, but it's not clear WHEN and WHY it is to be used. What is the use-case for the length aware paginator?

Activity icon

Replied to How To Modify Laravel's Returned Paginated Data ?

tried:

        $getPostsApiResponse->setData($postsArray); // see https://laravel.com/api/5.3/Illuminate/Http/JsonResponse.html#method_setData
Activity icon

Started a new Conversation How To Modify Laravel's Returned Paginated Data ?

My code is calling a Laravel API which returns data in this format:

{
    "current_page": 2,
    "data": [
        {
            "id": 36,
            "title": "Error perferendis aut velit quaerat.",
        },
        {
            "id": 124,
            "title": "Beatae nobis voluptatum incidunt animi voluptatem ea quod veniam.",
        }
    ],
    "first_page_url": "http://localhost:8000/api/v1/me/getPostsWithMyReactions?page=1",
    "from": 16,
    "last_page": 6,
    "last_page_url": "http://localhost:8000/api/v1/me/getPostsWithMyReactions?page=6",
    "next_page_url": "http://localhost:8000/api/v1/me/getPostsWithMyReactions?page=3",
    "path": "http://localhost:8000/api/v1/me/getPostsWithMyReactions",
    "per_page": 15,
    "prev_page_url": "http://localhost:8000/api/v1/me/getPostsWithMyReactions?page=1",
    "to": 30,
    "total": 78
}

After the result is returned, I would like to APPEND to the 'data' key while preserving the rest of the meta data for Laravel's pagination.

So, this is my desired result:

{
    "current_page": 2,
    "data": [
        {
            "id": 36,
            "title": "Error perferendis aut velit quaerat.",
            "bookmarked": 1,
        },
        {
            "id": 124,
            "title": "Beatae nobis voluptatum incidunt animi voluptatem ea quod veniam.",
            "bookmarked": 1,
        }
    ],
    "first_page_url": "http://localhost:8000/api/v1/me/getPostsWithMyReactions?page=1",
    "from": 16,
    "last_page": 6,
    "last_page_url": "http://localhost:8000/api/v1/me/getPostsWithMyReactions?page=6",
    "next_page_url": "http://localhost:8000/api/v1/me/getPostsWithMyReactions?page=3",
    "path": "http://localhost:8000/api/v1/me/getPostsWithMyReactions",
    "per_page": 15,
    "prev_page_url": "http://localhost:8000/api/v1/me/getPostsWithMyReactions?page=1",
    "to": 30,
    "total": 78
}

However, doing the following doesn't quite cut it:

$postsArray = $getPostsApiResponse->getData()->data;
foreach ($postsArray as $postObj) {
    $postObj->bookmarked = 1;
}
return $getPostsApiResponse;

Here, if I return $getPostsApiResponse, the data remains unchanged ("bookmarked": 1 isn't present). If I return $postsArray, the data is changed (it has "bookmarked": 1 in all the array's keys), but I lose all the pagination metadata (first_page_url, from, to, etc).

Does anyone know of a way to modify the data key while preserving the rest of the metadata? Ideally in a clean (the Laravel) way? Thanks for your help!

Activity icon

Awarded Best Reply on Why Does This Fail? (Retrieving Return Data From An API Response)

Here's the solution:

$result->getData(); // This fails.
$result->getData()->data; // this works

No idea why, but it works.

Activity icon

Replied to Why Does This Fail? (Retrieving Return Data From An API Response)

Here's the solution:

$result->getData(); // This fails.
$result->getData()->data; // this works

No idea why, but it works.

Activity icon

Started a new Conversation Why Does This Fail? (Retrieving Return Data From An API Response)

Hopefully a simple question...but this one has been driving me a bit nuts. I am trying to retrieve the return data from an API response. In this example, hardcoded to:

$returnData=[];
// $returnData['posts'] = null;
$result = (new PostResource($returnData))->response()->setStatusCode(Response::HTTP_OK);
return $result; // this is what the API returns

If the caller tries to access the API return data like this:

$result->getData(); // This fails.

Error:

UnexpectedValueException: The Response content must be a string or object implementing __toString(), "object" given. 

Why??

Dec
19
1 month ago
Activity icon

Replied to Error Running Cron Commands To Connect With MySQL8 Database?

@pt-83 check out what I have marked as "Best Answer"..that explains everything step by step and should help you!

Dec
15
1 month ago
Activity icon

Started a new Conversation Vue: Making Props Passed From Parent > Child Reactive After Mounted() Is Called

I have a parent that passes a prop to a child:

          <post-author-card
            :userData="postAuthorData"
:amIFollowingTheAuthor="amIFollowingTheAuthor"
          />

data() initializes the value to false:

  data() {
    return {
      amIFollowingTheAuthor: false,
    };
  },

And then in mounted(), an ajax request is made and the prop value changes:

this.amIFollowingTheAuthor = true;

However, the child component post-author-card still sees the prop value as false. Why?

I would like the value passed into the prop to change after the mounted() hook is called. How can I do this? What am I missing?

Dec
05
1 month ago
Activity icon

Started a new Conversation MySQL Trigger To Keep Num_comments (across A Nested Comment Tree) Up-to-date When A Comment Is Inserted / Deleted

I have a nested structure of comments. A comment can be made on either a post, or on some other comment (or sub-comment).

Therefore, the possible values for comments.commentable_type can be set to either: App\Post or App\Comment

comments.commentable_id is the id of the parent (Post or Comment) that the current comment was made on.

Each post has a field (num_comments) for the count of the number of comments + sub-comments under it. Similarly: Each comment has a field (num_comments) for the count of the number of comments + sub-comments under it. Note that num_comments is NOT a count of just the direct children (child comments) at the current depth. It should be an aggregate count of all comments below the current depth of the nested tree.

Here's my schema:

CREATE TABLE `posts` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `body` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `num_comments` int(11) NOT NULL,
  `num_likes` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `user_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `user_fk_403952` (`user_id`),
  CONSTRAINT `user_fk_403952` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=452 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `comments` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `body` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `is_removed` tinyint(1) DEFAULT '0',
  `comment_hash` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `num_comments` int(11) NOT NULL,
  `num_likes` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `user_id` int(10) unsigned NOT NULL,
  `commentable_type` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `commentable_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `comment_userid_commenthash_unique` (`user_id`,`comment_hash`),
  KEY `post_fk_655895` (`post_id`),
  CONSTRAINT `post_fk_655895` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),
  CONSTRAINT `user_fk_369255` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3314 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

The problem:

I need to create a MySQL trigger that would do the following: When a new comment, comment_B, is ADDED (on another comment, comment_A), we want to update: num_comments for comment_A (should update from 2 to 3, in this example) num_comments for comment_A's parent comment (comment_X in this example, should update from 7 to 8) and so on, up the chain, until we reach the post (Post_1 in this example)

Before Adding Comment_B:

Post_1 (num_comments=12)
|---comment_X (num_comments=7)
|        |-------comment_X1 (num_comments=1)
|        |           |-------comment_XX1 (num_comments=0)
|        |           
|        |-------comment_X2 (num_comments=0)
|        |-------comment_X3 (num_comments=0)
|        |
|        |-------comment_A (num_comments=2)
|                    |-------comment_A1 (num_comments=0)
|                    |-------comment_A2 (num_comments=0)
|
|---comment_Y (num_comments=1)
|        |-------comment_YY (num_comments=0)
|
|---comment_Z (num_comments=1)
|        |-------comment_ZZ (num_comments=0)

After Adding Comment_B:

Post_1 (num_comments=13)
|---comment_X (num_comments=8)
|        |-------comment_X1 (num_comments=1)
|        |           |-------comment_XX1 (num_comments=0)
|        |           
|        |-------comment_X2 (num_comments=0)
|        |-------comment_X3 (num_comments=0)
|        |
|        |-------comment_A (num_comments=3)
|                    |-------comment_A1 (num_comments=0)
|                    |-------comment_A2 (num_comments=0)
|                    |-------comment_B (num_comments=0)
|
|---comment_Y (num_comments=1)
|        |-------comment_YY (num_comments=0)
|
|---comment_Z (num_comments=1)
|        |-------comment_ZZ (num_comments=0)

(something similar should happen when a comment is DELETED): When a comment, comment_B, is DELETED (from another comment, comment_A), we want to update: num_comments for comment_A (should update from 3 to 2, in this example) num_comments for comment_A's parent comment (comment_X in this example, should update from 8 to 7) and so on, up the chain, until we reach the post (Post_1 in this example)

This is what I have tried so far (this is VERY bare-bones and doesn't even attempt to bubble the updates up the tree.....and yet this does not work)

-- Trigger to update comments.num_comments when comment added (to the comment or a comment belonging to the comments's sub-comment tree, identified by id)
CREATE TRIGGER update_comments_num_comments_on_insert_comment AFTER INSERT ON comments 
FOR EACH ROW
  UPDATE comments
    SET num_comments = (SELECT count(*) FROM comments WHERE deleted_at IS NULL AND is_removed=0 AND commentable_type="App\Comment" AND commentable_id=NEW.commentable_id)
   WHERE id=NEW.commentable_id;

And to test it, I tried the following comment insert:

-- Test: Add comment on Comment (which is a comment on post with id#1)
INSERT INTO comments(body, is_removed, num_comments, num_likes, created_at, user_id, post_id, commentable_type, commentable_id)
VALUES('Add Comment to Trigger update_comments_num_comments_on_insert_comment', 0, 0, 0, NOW(), 1, 1, "App\Comment", 1);

But it gives an error:

Can't update table 'comments' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

How can I get the trigger working, and have it so that it bubbles up and updates num_comments all the way up the nested structure of comments? Note: if we don't figure out how to update the num_comments on the Post, that's fine, I can easily create a separate trigger for that (it's relatively straightforward since I already have a post_id field for every comment, making it easy to query the comments table for post_id and update posts.num_comments every time a comment is inserted or deleted)

Does it make sense to use something like http://www.mysqltutorial.org/mysql-rollup/ ? A working MySQL trigger would be much appreciated.

Nov
26
1 month ago
Activity icon

Replied to Eloquent: How To Recursively Get The Details Of The Top Of The Tree For A Given Child

Hi @rodrigo.pedra, this is phenomenal, thank you for the detailed response. I spent the day thinking and trying out your solutions....

I do have to eventually get to the point of adding the post_id to the comments table....but for now, this works quite well :)


SELECT post_id
FROM (
    SELECT
        @post_id := (SELECT commentable_id FROM comments WHERE id = @comment_id and commentable_type = 'App\Post') AS post_id,
        @comment_id := (SELECT commentable_id FROM comments WHERE id = @comment_id and commentable_type = 'App\Comment') AS comment_id
    FROM
        comments, (SELECT @comment_id := 3500, @post_id := NULL) AS initialization
    WHERE @post_id IS NULL
) AS recurse
WHERE post_id IS NOT NULL;

Thank you again..and I will be coming back to this to try the other approaches you suggested.

Nov
24
1 month ago
Activity icon

Replied to Eloquent: How To Recursively Get The Details Of The Top Of The Tree For A Given Child

@rodrigo.pedra hi again! Thank you for your help last time, and now with this.

To address your first comment: You're right, I should probably include a post_id relation in my comments table / model, and then the problem becomes trivial. That also is the right way to do things, I'm sure. The problem is I don't have this relation already, and have a lot of code that is working fine without it. I don't have any unit tests (I know, I should add some, and that's on my roadmap...just not something I can get into now, because that would be quite a big tangent). To reduce the number of moving parts for now I am trying not to introduce a post_id field.

On your second comment: I am on MySQL 5.7 (sorry I should have mentioned this earlier)

$ mysql --version
mysql  Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using  EditLine wrapper

Is there a way to get your solution working with 5.7? Btw, what is newHasOne? I don't see that defined...curious if something is missing in the snippet. Again, thanks for your help.

Activity icon

Replied to Eloquent: How To Recursively Get The Details Of The Top Of The Tree For A Given Child

@artcore thank you for sharing your solution...I really appreciate it. I tried but could not get this to work....I am not sure how to use your code.

@jatinkumar thank you as well. I also tried your solution (a simple loop), with some edits:

        $commentId = 17;

        $k = [];
        do {
            $myComment = Comment::find($commentId);
            $k[] = $commentId;
            $commentId = $myComment['commentable_id'];
        } while ($commentId && $myComment['commentable_type'] == "App\Comment");

This works by navigating up the hierarchy, but wondering if there's a more efficient way....maybe with a single MySQL query..

Activity icon

Replied to Eloquent: How To Recursively Get The Details Of The Top Of The Tree For A Given Child

Agreed. Still trying to find an efficient MySQL query to do this, though. I found https://stackoverflow.com/questions/20215744/how-to-create-a-mysql-hierarchical-recursive-query and tried these

select @pv:=id as id, comment_hash, commentable_id, commentable_type, body
from comments
join
(select @pv:=15)tmp
where [email protected];

select
    @pv:=c1.id as id
  , c2.body as parent_body
  , c1.body body
  , c1.commentable_id
  , c1.commentable_type
from comments c1
join (select @pv:=15)tmp
left join comments c2 on c2.id=c1.commentable_id -- optional join to get parent name
where [email protected];


but honestly have no clue what I am doing. None of these are giving the result I expect (post id#5) I (think?) these are going down the hierarchy chain instead of up.

Activity icon

Replied to Eloquent: How To Recursively Get The Details Of The Top Of The Tree For A Given Child

@tray2 would something like this be efficient in your opinion? https://stackoverflow.com/a/29972187/11491070

Though I have to admit, I do find it a bit confusing. Any idea how I would need to modify the code in StackOverflow? Some sample code would be helpful!

Activity icon

Replied to Eloquent: How To Recursively Get The Details Of The Top Of The Tree For A Given Child

@tray2 yes I am using MySQL. Looking for a Laravel-way of doing the hierarchical queries.

Activity icon

Awarded Best Reply on Include External Javascript File In A Nuxt.js Page

Figured it out. Here's the complete solution that would work if we want to include a js (or mjs) file in ONE nuxt.js page only, instead of globally:

<template>
  <div class="container">

    <div>
        <dev-widget data-username="saurabhdaware"></dev-widget>
    </div>

  </div>
</template>

<script>

export default {
  layout: "default",

  head: {
    script: [
      {
        type: 'module',
        src: 'https://unpkg.com/[email protected]/dist/card.component.mjs'
      }
    ]
  },

};
</script>
Activity icon

Replied to Include External Javascript File In A Nuxt.js Page

Figured it out. Here's the complete solution that would work if we want to include a js (or mjs) file in ONE nuxt.js page only, instead of globally:

<template>
  <div class="container">

    <div>
        <dev-widget data-username="saurabhdaware"></dev-widget>
    </div>

  </div>
</template>

<script>

export default {
  layout: "default",

  head: {
    script: [
      {
        type: 'module',
        src: 'https://unpkg.com/[email protected]/dist/card.component.mjs'
      }
    ]
  },

};
</script>
Activity icon

Started a new Conversation Eloquent: How To Recursively Get The Details Of The Top Of The Tree For A Given Child

I have nested comments in my Laravel app (the Comment model is polymorphic, ie, the comment can be made to either a Post, or a Comment, as you can see in the example below with commentable_id and commentable_type)

id  comment_hash    commentable_type    commentable_id
17  cmpipb0         App\Comment         15
15  cmpipap         App\Comment         11
11  cmpipa4         App\Comment         1
1   cmpip7n         App\Post            5

Note: I am not storing (nor do I intend to store) the post_id as a separate field with each comment in the comments table.

Given a comment (#17 in this example), I need to recursively go "up" the tree of comments until I get the id / details of the Post that the comment belongs to. In the above example, we will be given the comment_hash "cmpipb0" for comment id#17, and I would like to get the Post with id "5", which is at the top of the tree of nested comments.

comment id #17 (with comment_hash: cmpipb0) which is the child of:
comment id #15 (with comment_hash: cmpipap) which is the child of:
comment id #11 (with comment_hash: cmpipa4) which is the child of:
comment id #1  (with comment_hash: cmpip7n) which is the child of:
post id #5

My Model code is below:

Comment.php:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Comment extends Model
{
    use SoftDeletes;

    public $table = 'comments';

    protected $dates = [
        'created_at',
        'updated_at',
        'deleted_at',
    ];

    protected $fillable = [
        'commentable_id',
        'commentable_type',
        'body',
        'user_id',
        'created_at',
        'updated_at',
        'deleted_at',
        'comment_hash',
    ];

    /**
     * Customize the primary key for comment model.
     * Enabling this results in 'out of memory'. See https://laracasts.com/discuss/channels/eloquent/changing-primary-key-of-a-polymorphic-comments-table-from-id-to-a-varchar-php-runs-out-of-memory
     */
    // protected $primaryKey = 'comment_hash';

    /**
     * Get the owning commentable model.
     */
    public function commentable()
    {
        return $this->morphTo();
    }

    /**
     * Get all of the comments (single-level, not recursively)
     */
    public function comments()
    {
        return $this->morphMany(Comment::class, 'commentable');
    }

}

Post.php:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model implements HasMedia
{
    public $table = 'posts';

    protected $dates = [
        'created_at',
        'updated_at',
        'deleted_at',
    ];

    protected $fillable = [
        'slug',
        'body',
        'title',
        'user_id',
        'updated_at',
        'created_at',
        'deleted_at',
    ];

    /**
     * Get all of the post's comments.
     */
    public function comments()
    {
        return $this->morphMany(Comment::class, 'commentable');
    }

}



What is the best way to do this in Laravel?

Activity icon

Started a new Conversation Include External Javascript File In A Nuxt.js Page

I have a relatively simple question.

I am trying to implement the widget from this codepen in Nuxt.js.

Here's my code, which works fine if I use RAW HTML:

<!DOCTYPE html>
<html>
<head></head>
<body>
  <dev-widget data-username="saurabhdaware"></dev-widget>
  <script src="https://unpkg.com/[email protected]/dist/card.component.mjs" type="module"></script>
</body>

</html>

But when I try to include this dev widget in my nuxt.js project, in one of my pages, it does not work.

Here is my code:

<template>
  <div class="container">

    <div>
        <dev-widget data-username="saurabhdaware"></dev-widget>
    </div>

  </div>
</template>

<script>

export default {
  layout: "default",
};
</script>

<script src="https://unpkg.com/[email protected]/dist/card.component.mjs" type="module"></script>

I keep getting an error:

Unknown custom element: < dev-widget >

Any idea what I am doing wrong here?

Nov
22
1 month ago
Activity icon

Replied to Nested Vue Components With Counts Of Direct Children And Nested Children

@fylzero @jlrdw @lelectrolux @rodrigo.pedra thank you so much for sharing your thoughts...

I spent a lot of time thinking about all your answers and experimenting....but I really wanted a front-end solution (to save the burden of having to maintain separate counts on the back-end side).

There's no denying that @rodrigo.pedra 's answer nailed it! Thank you!

Activity icon

Replied to What Arhitecture Should I Develop For A Laravel + VueJS Web Application?

Highly recommend that you look into nuxt.js - it takes a lot of the pain you're dealing with away. I personally am using nuxt (which is a vue.js framework) with laravel as a backend and could not be happier.

Nov
21
2 months ago
Activity icon

Replied to Nested Vue Components With Counts Of Direct Children And Nested Children

@fylzero I'm trying to do it when the components are initialized instead of using VueX.

  • Child initialized (mounted hook) = increment counter and bubble up to the parent.
  • Parent =increment it's own counter and bubble up to it's parent recursively..
  • and so on.

I haven't been able to get it to work though.

Activity icon

Started a new Conversation Nested Vue Components With Counts Of Direct Children And Nested Children

I am trying to implement nested comments in vue.js and nuxt.js.

  • Each comment can have one or more children comments.
  • Each child comment, can again, have one or more children comments.
  • Unlimited levels of nested comments is possible.

As you can see in the diagram I have attached, I would like each comment to "know" (for the sake of simplicity, to display) the following information:

  1. The depth of the comment (I have this working already). Example, all of the "top-level" comments are at depth=0, all their children are at depth=1, and so on.
  2. The number of direct children
  3. the number of children (including nested children, unlimited levels deep)

enter image description here

I came across this question on StackOverflow but it doesn't quite do the trick. Or maybe I am doing something wrong.

In case you want to take a look at my (very messy) code, here it is. However, I'm willing to start over, so appreciate any pointers on how to pass the data up / down the chain of nested comments (vue components). Some sample code would be great.

components/PostComment.vue:

<template>
<div>


  <div class="tw-flex tw-flex-wrap tw-justify-end">
    <div :class="indent" class="tw-w-full tw-flex">

      <div class="tw-font-bold tw-p-4 tw-border-gray-400 tw-border tw-rounded tw-text-right">
        <div class="kb-card-section">
          <div class="kb-card-section-content tw-flex tw-flex-wrap tw-items-center tw-text-left">

            <div class="tw-flex tw-w-full">
              <div class="tw-hidden md:tw-block md:tw-w-2/12 tw-text-right tw-my-auto">
                <div class="tw-flex">
                  <p class="tw-w-full tw-text-xs tw-text-gray-600 tw-text-right">children: {{ numNestedChildComments }}, depth: {{depth}}</p>
                </div>
              </div>
            </div>

          </div>

        </div>

      </div>

    </div>

    <div class="tw-w-full" v-if="commentData.nested_comments" v-for="nestedComment in commentData.nested_comments">
      <post-comment 
        :commentData="nestedComment"
        :depth="depth + 1"
        :numChildCommentsOfParent=numNestedChildComments
      />
    </div>

  </div>


</div>
</template>

<script>

export default {
  name: 'post-comment', // necessary for recursive components / nested comments to work
  props: {
    depth: {
      type: Number,
      required: true
    },
    postAuthorData: {
      type: Object,
      required: true
    },
    commentAuthorData: {
      type: Object,
      required: true
    },
    commentData: {
      type: Object,
      required: true
    },
    numChildCommentsOfParent: {
      type: Number,
      required: true
    },
  },
  data() {
    return {
      numNestedChildComments: this.numChildCommentsOfParent,
    }
  },
  mounted() {
    this.incrementNumParentComments();
  },
  methods: {
    incrementNumParentComments() {
      this.numNestedChildComments++;
      this.$emit('incrementNumParentComments');
    },
  },
  computed: {
    indent() {
      switch (this.depth) {
        case 0:
          return "tw-ml-0 tw-mt-1";
        case 1:
          return "tw-ml-4 tw-mt-1";
        case 2:
          return "tw-ml-8 tw-mt-1";
        case 3:
        default:
          return "tw-ml-12 tw-mt-1";
      }
    },
  },
}

</script>
Nov
09
2 months ago
Activity icon

Started a new Conversation Comparing Services For Cheap Cloud Hosting And Storage (Cloud / AWS / S3 / Amazon Cloudfront / ... ???)

Hi folks! 👋👋👋

Some questions for all you performance aficionados and AWS / Cloud experts out there.

I'm looking for a cheap (as close to free as possible) service for:

1. Hosting AND serving images. These images will be used on a website, in emails, etc. I want to plan for:

  • 100GB of added storage / month
  • 100M image views (GET requests) / month
  • 100K new image uploads (PUT / POST requests) / month

2. CDN / Edge caching - so as to serve requests as fast as possible. Here I am looking to reduce response times and website load times that end-users will experience.

AWS both has an amazing suite of products and at the same time is very difficult to get started with.AWS S3's pricing model is confusing. I did also play a bit with their calculator, but it's hard to say if I'm entering the numbers in correctly.

Q1: In the AWS ecosystem:

  • For S3: What is "Storage pricing" vs "Request Pricing"?
  • What is S3 Select and how is it different from S3?
  • What is S3 Intelligent-Tiering?
  • What is S3 Glacier?
  • And what about Amazon CloudFront?

Q2: Is AWS the best (and cheapest) available option? What about services like:

  • Cloudflare
  • Cloudinary
  • Photon by Jetpack etc?
  • Versus using my Linode server itself for hosting and serving images?
  • versus the 1000+ other options out there?

Thoughts on what service I should be using? Looking for advice from folks that are knowledgeable on the matter. 🙏🙏🙏

Activity icon

Replied to How Does Redfin Auto-detect My Google Accounts And Prompts Me To Sign-in With Google?

Also looks like Chrome's the only browser being supported.

Activity icon

Replied to How Does Redfin Auto-detect My Google Accounts And Prompts Me To Sign-in With Google?

Boom...thanks @bobbybouwmann I just needed to know what to Google for. It's funny, I still can't find their official docs.

Activity icon

Started a new Conversation How Does Redfin Auto-detect My Google Accounts And Prompts Me To Sign-in With Google?

I have regular "Login with Google" oAuth implemented (screenshot 1 below...you know, where you click a link, and are taken to a page or modal with a "Sign up with Google" button)

But I would like to do what Redfin is doing (Screenshot 2 below). How does Redfin auto-detect all of my Google accounts and show a tiny box at the top right as soon as I go to redfin.com? Is there an API or some way to do this?

Normal social login with Google

Redfin auto-detects my Google Accounts and Prompts me to sign-in with Google

Nov
07
2 months ago
Activity icon

Replied to Route List Not The Same As Web.php

@vincej perhaps if you can put up your project (or bits thereof) online - github ideally, others can help debug or at least replicate the problem.

Nov
06
2 months ago
Activity icon

Awarded Best Reply on Error Running Cron Commands To Connect With MySQL8 Database?

@jlrdw @sinnbeck I got it working on MySQL 8. Thank you both for your help..

It was painful but this is how I fixed it

Debugging:

$mysql --verbose --help | grep my.cnf

$ which mysql
/usr/local/bin/mysql

Resolution:

nano /usr/local/etc/my.cnf

Add: default-authentication-plugin=mysql_native_password

-------
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
default-authentication-plugin=mysql_native_password
------

Finally Run: brew services restart mysql

Activity icon

Replied to Error Running Cron Commands To Connect With MySQL8 Database?

Yes, and again, thank you both for caring to respond.

Activity icon

Replied to Error Running Cron Commands To Connect With MySQL8 Database?

@jlrdw @sinnbeck I got it working on MySQL 8. Thank you both for your help..

It was painful but this is how I fixed it

Debugging:

$mysql --verbose --help | grep my.cnf

$ which mysql
/usr/local/bin/mysql

Resolution:

nano /usr/local/etc/my.cnf

Add: default-authentication-plugin=mysql_native_password

-------
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
default-authentication-plugin=mysql_native_password
------

Finally Run: brew services restart mysql

Activity icon

Replied to Error Running Cron Commands To Connect With MySQL8 Database?

@jlrdw thanks for the response. The query does work if I run it manually.

I did find this I'm trying to do this right now, so I dont quite have it working yet.

Activity icon

Replied to Error Running Cron Commands To Connect With MySQL8 Database?

@jlrdw shouldn't it work with any data? I just tried without faker and same error


   Illuminate\Database\QueryException  : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: insert into `users` (`email`, `name`, `password`) values ([email protected]$

  at /Users/kp/Code/EXPLORATIONS/EMAILS_QUEUES_CACHING_REDIS/connecteev_laravel_email_campaigns_and_tracking_example/vendor/laravel/framework/src/Illuminate/Database/Connection.php:665
    661|         // If an exception occurs when attempting to run a query, we'll format the error
    662|         // message to include the bindings with SQL, which will make this exception a
    663|         // lot more helpful to the developer instead of just the database's errors.
    664|         catch (Exception $e) {
  > 665|             throw new QueryException(
    666|                 $query, $this->prepareBindings($bindings), $e
    667|             );
    668|         }
    669|

  Exception trace:

  1   PDOException::("PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]")
      /Users/kp/Code/EXPLORATIONS/EMAILS_QUEUES_CACHING_REDIS/connecteev_laravel_email_campaigns_and_tracking_example/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=__connecteev_laravel_email_campaigns_and_tracking_example", "testuser", "testuser", [])
      /Users/kp/Code/EXPLORATIONS/EMAILS_QUEUES_CACHING_REDIS/connecteev_laravel_email_campaigns_and_tracking_example/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  Please use the argument -v to see more details.



I'm just really puzzled by this.

Activity icon

Replied to Error Running Cron Commands To Connect With MySQL8 Database?

@sinnbeck thanks...yeah I did run the command with localhost and reloaded with FLUSH PRIVILEGES

I set up a test user for MySQL:

CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'testuser';
ALTER USER 'testuser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'testuser'; FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON * . * TO 'testuser'@'localhost';

I changed my db credentials in my .env and confirmed that Laravel is able to connect to the DB. However, the cron still fails :(

Activity icon

Replied to Error Running Cron Commands To Connect With MySQL8 Database?

@sinnbeck thank you. What did you mean to say when you started with "Cron looks like it should..."

Yes, I am using root as the username...so it is consistent.

Activity icon

Replied to Error Running Cron Commands To Connect With MySQL8 Database?

@sinnbeck

This is my crontab -e:

* * * * * cd /Users/kp/Code/EXPLORATIONS/EMAILS_QUEUES_CACHING_REDIS/connecteev_laravel_email_campaigns_and_tracking_example && php artisan schedule:run >> /Users/kp/Code/EXPLORATIONS/EMAILS_QUEUES_CACHING_REDIS/connecteev_laravel_email_campaigns_and_tracking_example/cron.out

Also, just checked. The users are the same in both cases.

I verified using "whoami" before php artisan schedule:run and also added this to the cron job:

            $schedule->exec('whoami')
            ->everyMinute()
            ->before(function () {
                echo "Task is about to start...\n";
            })
            ->after(function () {
                echo "Task is complete...\n";
            })
            ->onSuccess(function () {
                echo "The task succeeded...\n";
            })
            ->onFailure(function () {
                echo "The task failed...\n";
            })
            ->appendOutputTo('whoami_logs.txt')

And whoamilogs.txt shows the same username as when I run php artisan schedule:run manually.

Activity icon

Replied to Error Running Cron Commands To Connect With MySQL8 Database?

Thanks @jlrdw but it didn't work.

I tried adding

            'modes'       => [
                'ONLY_FULL_GROUP_BY',
                'STRICT_TRANS_TABLES',
                'NO_ZERO_IN_DATE',
                'NO_ZERO_DATE',
                'ERROR_FOR_DIVISION_BY_ZERO',
                'NO_ENGINE_SUBSTITUTION',
            ],

to my database.php

Also tried this

#DB_HOST=127.0.0.1
DB_HOST=localhost

in my .env and restarted laravel

Also tried restarting MySQL. Nothing worked.

Activity icon

Started a new Conversation Error Running Cron Commands To Connect With MySQL8 Database?

I am seeing a rather strange issue when running a Laravel Command. I am trying to do a simple insert into MySQL 8 with a cron command.

In app/Console/Kernel.php:

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

use Illuminate\Support\Facades\DB;
use Faker\Generator as Faker;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function (Faker $faker) {
            DB::table('users')->insert(
                [
                    'email' => $faker->unique()->safeEmail,
                    'name' => $faker->username,
                    'password' => $faker->password,
                ]
            );
        })->everyMinute();
    }

If I execute php artisan schedule:run from the command line, everything works beautifully, and a new entry gets added to the users table.

However, my cron job (which is configured correctly and is able to run other commands) errors out:

Running scheduled command: Closure

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: insert into `users` (`email`, `name`, `password`) values (nolan.maxi$

  at /Users/kunalpunjabi/Code/EXPLORATIONS/EMAILS_QUEUES_CACHING_REDIS/connecteev_laravel_email_campaigns_and_tracking_example/vendor/laravel/framework/src/Illuminate/Database/Connection.php:665
    661|         // If an exception occurs when attempting to run a query, we'll format the error
    662|         // message to include the bindings with SQL, which will make this exception a
    663|         // lot more helpful to the developer instead of just the database's errors.
    664|         catch (Exception $e) {
  > 665|             throw new QueryException(
    666|                 $query, $this->prepareBindings($bindings), $e
    667|             );
    668|         }
    669|

  Exception trace:

  1   App\Console\Kernel::App\Console\{closure}(Object(Faker\Generator))
      [internal]:0

  2   App\Console\Kernel::App\Console\{closure}(Object(Faker\Generator))
      [internal]:0

  Please use the argument -v to see more details.

Note: As per this recommendation, I already tried this:

        // On MySQL 8.0, may need to run: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; FLUSH PRIVILEGES; // replace 'root' with MySQL password

But it did not help. I am seeing the same error.

Any advice on what the problem might be?

Nov
01
2 months ago
Activity icon

Replied to Way To Defer Laravel's API Request Validation?

It's similar...thanks. I marked your answer the best answer.

Activity icon

Replied to Way To Defer Laravel's API Request Validation?

Thanks but that didn't quite work.

Solved it by doing this.

        // Validate the request with the rules() set in StorePostRequest.php
        $storePostRequest = new StorePostRequest();
        $validator = Validator::make($requestData, $storePostRequest->rules());
        if ($validator->fails()) {
            return response($validator->errors(), Response::HTTP_BAD_REQUEST);
        }
        $post = Post::create($requestData);
Oct
31
2 months ago
Activity icon

Started a new Conversation Way To Defer Laravel's API Request Validation?

I have an API resource that accepts a request as such:

 public function create(StorePostRequest $request) {
 }

The problem is, when I send a POST request to this create() endpoint, the rules() defined in StorePostRequest.php kick in before the method is even called. I want to do some pre-validation and THEN validate with the rules() in the StorePostRequest.

The rules() that are defined in StorePostRequest.php kick in before the create() method is even called.

    public function rules()
    {
        return [
            'title'                  => [
                'min:10',
                'max:255',
                'required',
            ],
            'slug'                   => [
                'min:10',
                'max:255',
                'required',
                // 'unique:posts',
            ],
            'user_id'                => [
                'required',
                'integer',
            ],
        ];

For example, the user_id should be retrieved from the Auth() session, and not get passed in. But I do want the rule to be there when the data gets stored to the posts table.

So, I changed the API to:

    // Note: if you accept a StorePostRequest $request, it automatically pre-validates based on rules() in StorePostRequest
    public function create(Request $request)
    {
        $loggedinUser = auth()->user();
        if (!$loggedinUser) {
            return response(["error" => "User is not logged in. User needs to be logged in to use this API."], Response::HTTP_FORBIDDEN);
        }
        $loggedinUserId = $loggedinUser->id;

        $requestData = $request->all();
        if (!isset($requestData['title'])) {
            return response(["error" => "title is required"], Response::HTTP_BAD_REQUEST);
        }
        if (!isset($requestData['body'])) {
            return response(["error" => "body is required"], Response::HTTP_BAD_REQUEST);
        }
        if (!isset($requestData['status'])) {
            return response(["error" => "status is required"], Response::HTTP_BAD_REQUEST);
        }
        $requestData['slug'] = $this->createUniquePostSlug($request->title);
        $requestData['user_id'] = $loggedinUserId;
        $requestData['description'] = $request->title;
        $requestData['reading_time_minutes'] = ceil(str_word_count(strip_tags($requestData['body'])) / 200); // assuming an average reading speed of 200 wpm

        $post = Post::create($requestData);

        return (new PostResource($post))
            ->response()
            ->setStatusCode(Response::HTTP_CREATED);
    }

However now I have to do a bunch of manual validation (using isset($requestData) like I'm doing above. I want the StorePostRequest rules to kick in, but after I do some request validation myself. Is there a way to do this? Maybe there's a way to cast the Request object to the StorePostRequest? THoughts? And thanks in advance.

Oct
20
3 months ago
Activity icon

Replied to Getting Username (Nickname) For Google / Linkedin Using Socialite

@gamerfac3 I've already read those docs, this is what I am doing to request the appropriate scopes:

        switch($service) {
            case 'github':
                // https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/
                $scopesArray = ['user:email', 'read:user']; // Socialite default: ['user:email']
                break;
            case 'google':
                // https://developers.google.com/identity/protocols/googlescopes#google_sign-in
                $scopesArray = ['openid', 'profile', 'email']; // Socialite default: ['openid', 'profile', 'email']
                break;
            case 'linkedin':
                // https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin#authenticating-members
                $scopesArray = ['r_liteprofile', 'r_emailaddress']; // Socialite default: ['r_liteprofile', 'r_emailaddress']
                break;
            default:
                return response(['error' => 'Yo! Invalid service, ' . $service . ' is not supported.'], Response::HTTP_BAD_REQUEST);
                break;
        }
        Socialite::driver($service)->setScopes($scopesArray);

The problem is I don't get a username / nickname back for LinkedIn or Google:

            $socialiteUser = Socialite::driver($service)->userFromToken($request->providerToken);
            $socialUsername = $socialiteUser->getNickname();

It comes back as NULL, eventhough I have usernames for both these services.

Oct
19
3 months ago
Activity icon

Started a new Conversation Getting Extended Profile Data Back From Linkedin, Google Etc Using Laravel Socialite

I'm using the latest version of Laravel Socialite to log a user into:

  • Linkedin
  • Google

How can I request extended data to be returned back from any / all of these services? For example: In the case of Linkedin, I am interested in the Linkedin profile data that includes:

  1. Location
  2. Current TItle
  3. Current Company etc In the case of Google, I am interested in:
  4. Gender
  5. Birthday
  6. Location

These are the authorization URLs I request at the start of my oAuth flow.

    // Google:  https://accounts.google.com/signin/oauth?client_id=833332220512-u1meuuiposp1gdk8uh80hn27dh41qkpa.apps.googleusercontent.com&as=wxbImJ-i9ngw6UZft-Y9Yw&destination=http://localhost:8000&approval_state=!ChRhZjRx3kVTNDVnbU1pTG5ucnhFUBIfTTNqTmItU2dnQ01Ta013TWpqbVNUV1Z5NFcxcTNoWQ%E2%88%99AJDr988AAAAAXa0BVq86VO6bEvcHskT34vAim0aj9mSj&oauthgdpr=1&xsrfsig=ChkAeAh8T9wlk22s0o1wZ_EL4vgTgDUpAfEEg5hcHByb3ZhbF9zdGF0ZRILZGVzdGluYXRpb24SBXNvYWN1Eg9vYXV0aHJpc2t5c2NvcGU
    // Linkein: https://www.linkedin.com/oauth/v2/authorization?client_id=36522h97mc5oew&redirect_uri=http://localhost:8000/api/v1/auth/login/linkedin/callback&response_type=code&scope=r_liteprofile%20r_emailaddress%20w_member_social


I've already read the docs, this is what I am doing to request the appropriate scopes:

        switch($service) {
            case 'github':
                // https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/
                $scopesArray = ['user:email', 'read:user']; // Socialite default: ['user:email']
                break;
            case 'google':
                // https://developers.google.com/identity/protocols/googlescopes#google_sign-in
                $scopesArray = ['openid', 'profile', 'email']; // Socialite default: ['openid', 'profile', 'email']
                break;
            case 'linkedin':
                // https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin#authenticating-members
                $scopesArray = ['r_liteprofile', 'r_emailaddress']; // Socialite default: ['r_liteprofile', 'r_emailaddress']
                break;
            default:
                return response(['error' => 'Yo! Invalid service, ' . $service . ' is not supported.'], Response::HTTP_BAD_REQUEST);
                break;
        }
        Socialite::driver($service)->setScopes($scopesArray);

Is what I'm trying possible, and if so, how can I get this additional data back?