Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

DanielRoenfeldt

DanielRoenfeldt

Member Since 8 Months Ago

Viborg

Experience Points
12,280
Total
Experience

2,720 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
113
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 3
12,280 XP
Nov
18
1 week ago
Activity icon

Started a new Conversation Route Model Binding - Using 2 Fields At The Same Time

[Laravel 6]

I've got an Article model which is currently using the slug column as the "route key" binding. I needed this in order to benefit from having SEO-friendly routes. I achieved this as per the official docs, i.e.

/**
 * Get the route key for the model.
 *
 * @return string
 */
public function getRouteKeyName()
{
    return 'slug';
}

Now, all's good, except I recently added a new uuid field in the Article model's table, the value of which I'm aiming to use together with the slug value to construct truly unique URIs, which are still kept SEO-friendly.

Let me explain what I mean. Let's assume a random Article instance has the value of the slug field set to "a-demo-article", while its value of the uuid field is "40207e78-ca65-4402-9505-cfe9e8bda788".

The way it's working now, the Article's permalink would beblog.test/a-demo-article.

What I need, is the permalink to be something like blog.test/40207e78-ca65-4402-9505-cfe9e8bda788-a-demo-article.

I'm hoping I'm making sense.

How would I achieve this sort of "concatenated route key binding"? Any thoughts?

Thanks so much!

Oct
20
1 month ago
Activity icon

Replied to Allowed Memory Size Of 1610612736 Bytes Exhausted (tried To Allocate 4096 Bytes)

Me, yesterday: "Weird error, prolly easy to fix though". Me, 20-ish hours later: "Aaargh! Nothing works!!!" Me, 5 minutes ago: "@snapey sir, you are a GOD!"

Aug
15
3 months ago
Activity icon

Replied to Asyncrhonous Component Instance Inside Parent Component

Outstanding! I ❤️ this community!

Aug
14
3 months ago
Activity icon

Replied to Asyncrhonous Component Instance Inside Parent Component

Brilliant! I never thought pushing a "programatically-created" component into an existing list could consist in such a simple and straightforward object-driven approach! It's so funny that all I was doing, was trying to re-invent the wheel.

Now if only I could figure out how to have the new comment getting visutally "pushed" as the first one, that is, on top of the existing ones, that would be perfect :) Any suggestions?

In any case, you, sir, are a legend!

Activity icon

Replied to Asyncrhonous Component Instance Inside Parent Component

Yes, that's exactly what I'm trying to achieve. But what do you exactly mean by "update your comments"? Could you provide me with an example of how that would be done? And please take into account that the new comment is supposed to be "built" through (or via) the <comment-item> component. Or am I misunderstanding the way this is supposed to work? :) Thanks so much!

Activity icon

Replied to Asyncrhonous Component Instance Inside Parent Component

Any ideas on how could I instantiate a component programatically, in an asynchronous way, inside another component?

I would highly appreciate any help with this one!

Aug
13
3 months ago
Activity icon

Started a new Conversation Asyncrhonous Component Instance Inside Parent Component

I've got a <comments-list></comments-list> component which loops through a Laravel Collection object of existing comments that are associated with a BlogPost model. I'm then instantiating each "comment" entity into its own element driven by a <comment-item></comment-item> component.

My intention is to provide visitors with the capability of writing comments, which (once sent through via axios and then validated through a Laravel Cotroller method) would finally appear into the list of the existing comments, as new <comment-item></comment-item> items that get appeded to the <comments-list></comments-list> element.

I've been following this guide which explains how a Vue Component can be programatically created.

From my limited understanding, a major problem with that approach is, the programatically-created <comment-item></comment-item> element is getting instantiated and mounted along with its <comments-list></comments-list> container, instead of it being created upon a successful response from the axios call.

In any case, here's my code - let me know if there's anything that doesn't quite make sense. Note that I haven't added any axios-processing in here, just so that I can illustrate my use-case scenario as cleanly as possible.

// resources/assets/js/app.js

window.Vue = require('vue')

Vue.component('comment-item', require('./components/CommentItem').default);
Vue.component( 'comments-list', require('./components/CommentsList').default );

const app = new Vue({
  el: '#app'
});
<!-- resources/views/blogposts/view.blade.php -->

@section('comments')

  <!-- ... -->
  
  <!-- $comments is the Eloquent Collection of "comments" -->
  <comments-list
        :comments-collection="{{ $comments }}"
  ></comments-list>

  <!-- ... -->
<!-- resources/assets/js/components/CommentsList.vue -->

<template>
  <div ref="commentsWrapper" class="comments-list">
  	
    <comment-item
        v-for="comment in comments"
        :key="comment.id"
        		
        :avatar="comment.user.avatar"
        :name="comment.user.name"
    >
    <template slot="the_body">{{ comment.body }}</template>
        </comment-item>
        	
        <!-- Just for testing -->
        <button @click="pushDemoComment">Push new Comment asynchronously</button>
    </div>
</template>

<script>
    import CommentItem from "./CommentItem";
    
    import Vue from 'vue';
        let ComponentClass = Vue.extend(CommentItem);
        const newComment = new ComponentClass({
            propsData: {
                avatar: 'path/to/image.jpg',
                name: 'Some Name',
            }
        });
        
        newComment.$slots.the_body = ['Lorem ipsum some random text in here...'];
        newComment.$mount();
	
	
        export default {
            name: "CommentsList",
            
            props: {
                commentsCollection: { type: Array, required: true }
            },
            
            methods: {
                pushDemoComment() {
                    console.log('Demo comment pushed!');
                    this.$refs.commentsWrapper.prepend( newComment.$el );
            }
        },
        	
        components: {
            'comment-item': CommentItem,
        }
    }
</script>
<!-- resources/assets/js/components/CommentItem.vue -->

<template>
    <div class="comment-item">
        <div class="avatar">
            <img :src="handleAvatar" :alt="name">
        </div>
        	
        <span class="name" v-text="name"></span>
        
        <slot name="the_body"></div>
    </div>
</template>

<script>
    export default {
        name: "CommentItem",
        
        props: {
            avatar: { type: String, required: true },
            name: { type: String, required: true },
        },
        
        methods: {
            handleAvatar() {
                // ... some avatar handling logic ...
                		
                return '../' + this.avatar;
            }
        },
        
        components: {
            'comment-item': CommentItem,
        }
    }
</script>
Aug
05
3 months ago
Activity icon

Replied to How To Use DiffForHumans() In Vue

Heads up: if you're trying to use @kkhicher1 's solution in Laravel 6.x, there's a caveat: it only works on Laravel 7+. The CastsAttributes interface wasn't implemented before Laravel 7.

Jul
16
4 months ago
Activity icon

Replied to How Do You FTP Into Your Forge Server?

@bradfields Brilliant! I can confirm that it works flawlessly with Transmit.

Jun
23
5 months ago
Activity icon

Replied to Help Converting CURL Request Into Guzzle Request

Alright, that seems to have solved my problem, as in, I'm not getting the 401 Unauthorized error anymore. But let me get this straight: the two strings representing the user's first and last name, they should be sent as part of the 'body' parameter of the request, like so:

$response = $client->get("https://xxxxxxx.xx.auth0.com/api/v2/users/{$userId}", [
	'headers' => [
		"Authorization" => "Bearer {$temp_token}",
		"Cache-Control" => "no-cache",
		"Accept" => "application/json",
	],
	'body' => "{ \"given_name\": $request->firstName, \"family_name\": $request->lastName }"
]);

Is my assumption correct? Because if it is, then the data is not being pushed to the Auth0 server. I'm a bit confused here...

PS: I totally forgot about including PHP variables within strings within curly braces, so thank you for helping me write a more efficient code! :)

Activity icon

Started a new Conversation Help Converting CURL Request Into Guzzle Request

Given this cURL-driven request:

$user_id = "auth0|xxxxxxxxxxxxxxxxxxxx";
$temp_token = "xxxxxxxxxxxxxxx..........xxxxxxxxxxxxxx";

$curl = curl_init();
		
curl_setopt_array($curl, array(
	CURLOPT_URL => "https://xxxxxxx.xx.auth0.com/api/v2/users/" . $user_id,
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => "",
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 30,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => "PATCH",
	CURLOPT_POSTFIELDS => "{ \"given_name\": $request->firstName, \"family_name\": $request->lastName }",
	CURLOPT_HTTPHEADER => array(
		"authorization: Bearer " . $temp_token,
		"cache-control: no-cache",
		"content-type: application/json"
	),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
	echo "cURL Error #:" . $err;
} else {
	echo $response;
}

I've been trying to convert it into a Guzzle-driven request, like so:

$headers = [
	"Authorization" => "Bearer " . $temp_token,
	"Cache-Control" => "no-cache",
	"Accept" => "application/json",
];

$g_uri = "https://xxxxxxx.xx.auth0.com/api/v2/users/" . $userId;

$client = new Client();
$g_request = $client->get($g_uri);

$g_request->getCurlOptions()->set(CURLOPT_RETURNTRANSFER, true);
$g_request->getCurlOptions()->set(CURLOPT_ENCODING, "");
$g_request->getCurlOptions()->set(CURLOPT_MAXREDIRS, 10);
$g_request->getCurlOptions()->set(CURLOPT_TIMEOUT, 30);
$g_request->getCurlOptions()->set(CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$g_request->getCurlOptions()->set(CURLOPT_CUSTOMREQUEST, "PATCH");
$g_request->getCurlOptions()->set(CURLOPT_POSTFIELDS, "{ \"given_name\": $request->firstName, \"family_name\": $request->lastName }");
$g_request->getCurlOptions()->set(CURLOPT_HTTPHEADER, $headers);

$g_response = $g_request->send();

echo $g_response;

But it's throwing back a 401 Unauthorized exception, unlike the original cURL request. Is there a better way of handling this?

FYI: I'm using Laravel 6.x.

Many thanks.