Danlog

Danlog

Full stack developer. at Home-office ☕

Member Since 4 Years Ago

Experience Points
8,830
Total
Experience

1,170 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
69
Lessons
Completed
Best Reply Awards
1
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,830 XP
Jul
22
4 months ago
Activity icon

Replied to Laravel-echo-server Not Working In Server

I just opened 6002, but nothing still. Should I edit the config on laravel-echo-server.json (the port)? You're my only hope to fix this...

Activity icon

Started a new Conversation Laravel-echo-server Not Working In Server

Hey, I tried to deploy, installed laravel-echo-server, but apparently the app is not receiving any connections (no one can join any channel).

I also tried following https://laracasts.com/index.php/discuss/channels/forge/laravel-echo-server-installation-on-forge-with-ssl-enabled-with-the-redis-broadcast-driver? but didn't work out for me.

Do you guys have any idea why no connections are being received?

edit: it is not receiving any events either

Jul
19
4 months ago
Activity icon

Replied to How To Get The Models That Are Due To 3 Days Or Lower?

I did it a bit different:

        $now = date(Carbon::now());
        $to = date(Carbon::now()->addDays(3));
        $urgent = Homework::whereBetween('duedate', [$now, $to])->with('user')->count();
Activity icon

Started a new Conversation How To Get The Models That Are Due To 3 Days Or Lower?

I'm trying to do it this way, but apparently, it's not the solution:

$urgent = Homework::where('duedate', '<=3', now())->with('user')->count();
Jun
30
4 months ago
Activity icon

Started a new Conversation How To Get Latest In This Case?

Hello, I'm trying to fetch latest first, but I'm not sure how to get the latest first in this case:

return new GroupResource($group->load('messages.user'));

Jun
29
5 months ago
Activity icon

Started a new Conversation How To Return A Resource In An Event?

Hello, yesterday I was able to achieve resources and getting a JSON structured the way I needed to for a chat app, the problem is now to make this possible for it to work with web-sockets.

For example, when I retrieve the messages of a group, I get the JSON this way, which is absolutely needed for it to work with the front-end:

{
  "data": {
    "id": 1,
    "messages": [
      {
        "_id": 1,
        "text": "Hey!",
        "createdAt": "2020-06-04T18:45:06.000000Z",
        "user": { // Array inside the array.
          "_id": 1,
          "name": "Daniel Logvin",
          "email": "[email protected]",
          "created_at": "2020-06-04T17:13:19.000000Z",
          "updated_at": "2020-06-04T18:12:25.000000Z"
        }
      },

This is retrieved this way:

public function show(Group $group)
    {
        return new GroupResource($group->load('messages.user'));
    }

Now, when I "send" a message, I summon the event:

public function send(Request $request, Group $group){

        $message = new Message([
            'user_id' => Auth::user()->id,
            'group_id' => $request->groupId,
            'message' => $request->message
        ]);
        $message->save();

        event(new MessageSent($message)); // here.
        return response()->json([
        "code" => 200,
        "message" => "Message successfully sent"
        ]);
    }

The problem here is that when the event is called, I need to return the message in that same structure, but I'm not sure how to use a resource and make it work with an Event in this case.

I've tried searching this for 3 hours straight and no luck yet, so that's why I'm asking.

Thank you in advance. In case you're going to try to provide an answer, please respond the follow ups

Jun
28
5 months ago
Activity icon

Replied to 404 API Route When Route Is Called Through AXIOS Or Insomnia

Also, ran the command and............

| | POST | api/auth/send/group/{id} | | App\Http\Controllers\[email protected] | api

Activity icon

Replied to 404 API Route When Route Is Called Through AXIOS Or Insomnia

Sorry, didn't include it up there. In the beginning you can find the following:

      'middleware' => 'auth:api', 'verified'
    ], function() {
Activity icon

Started a new Conversation 404 API Route When Route Is Called Through AXIOS Or Insomnia

Hello, hope everyone is doing fine. I'm getting a little problem that is confusing me a lot.

Well, in my api.php route folder, I got the following: Route::post('send/group/{id}', '[email protected]'); and it appears to be working when I put it in the browser, I do get the The GET method is not supported for this route. Supported methods: POST. .

But when I try to execute it in Insomnia, I get a 404.

Any ideas of why this is happening?

In the browser I'm doing it the following way: http://page.test/api/auth/send/group/1

In axios:

axios.post(`http://page.test/api/auth/send/group/${this.props.navigation.getParam('id')}`,
                        {
                            message: this.state.message
                        },
                        {
                            headers: {
                                'Authorization': access,
                            }
                        })

and in insomnia:

http://page.test/api/auth/send/group/1

Activity icon

Awarded Best Reply on How To Add Data To A Resource?

Solved:

return new GroupResource($group->load('messages'));

Activity icon

Replied to How To Add Data To A Resource?

Solved:

return new GroupResource($group->load('messages'));

Activity icon

Replied to How To Add Data To A Resource?

I've already checked the docs and got super confused, that's why I decided to jump here and ask :)

The group hasMany messages, that's why I'm trying to get all the messages and, if possible, sort by latest.

Sorry, but I've been trying for already 3 hours and still cant get anything. Help would be appreciated!

Activity icon

Started a new Conversation How To Add Data To A Resource?

Hey guys, I'm trying to get all messages in a resource, but it is saying is Property [id] does not exist on this collection instance. so, I'm doing the following:

public function show(Group $group)
    {
        return new GroupResource($group->messages);
    }

and in my resource

<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Http\Resources\User as UserResource;

class Group extends JsonResource
{
    /**
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            '_id' => $this->id, // This has the problem, and this means everything else has the same problem too
            'text' => $this->message,
            'createdAt' => $this->created_at,
            // define the User resource too
            'user' => UserResource::collection($this->users)
        ];
    }
}

I would really appreciate if I get some help over here!

Activity icon

Replied to REST API Get A Model With A Model Inside Of It:

So, I made resources and now I'm getting the array I need:

{
  "data": {
    "_id": null,
    "text": null,
    "createdAt": null,
    "user": []
  }
}

Resources:

Group.php

<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Http\Resources\User as UserResource;

class Group extends JsonResource
{
    /**
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            '_id' => $this->id,
            'text' => $this->text,
            'createdAt' => $this->created_at,
            // define the User resource too
            'user' => UserResource::collection($this->users)
        ];
    }
}
Activity icon

Replied to REST API Get A Model With A Model Inside Of It:

The current code works, but I need to put the user inside the message that is being retrieved :)

Activity icon

Started a new Conversation REST API Get A Model With A Model Inside Of It:

I'm trying to retrieve a model the following way:

        _id: 1, // ====> The model (example: Message)
          text: 'My message',
          createdAt: new Date(Date.UTC(2016, 5, 11, 17, 20, 0)),
          user: { // ====> The model in the relationship, in this case, the USER
            _id: 2,
            name: 'React Native',
            avatar: 'https://facebook.github.io/react/img/logo_og.png',
          },

How is it possible for me to achieve this with laravel?

My current code looks this way:

public function show($id){
        $id = Group::where('id', $id)->first();
        return response()->json([
            'messages' => $id->messages,
        ]);
    }
Jun
20
5 months ago
Jun
04
5 months ago
Activity icon

Awarded Best Reply on Crash After Updating Laravel To The Latest Version.

Apparently, now I have to define explicitly which table I'll be working with.

Now works after using public $table = "homeworks"

Submitted an issue asking why it worked before and why not now.

Activity icon

Replied to Crash After Updating Laravel To The Latest Version.

Apparently, now I have to define explicitly which table I'll be working with.

Now works after using public $table = "homeworks"

Submitted an issue asking why it worked before and why not now.

Activity icon

Replied to Crash After Updating Laravel To The Latest Version.

I got $results = Subject::with(['user'])->where('user_id', $user_id)->withCount('homeworks'); the table homeworks does exist.

Activity icon

Started a new Conversation Crash After Updating Laravel To The Latest Version.

Hello guys, ran composer update and I started getting SQLSTATE[42S02]: Base table or view not found: 1146 Table 'homewrk.homework' doesn't exist (everything is typed correctly because it used to work before the update).

The piece of code that its generating the error is the following:

public function dashboard()
    {
        $user = Auth::user();
        $user_id = Auth::id();
        $results = Subject::with(['user'])->where('user_id', $user_id)->withCount('homeworks');
        $subjects = $results->latest()->get(); // This line is being marked
        return view('dashboard.dashboard', compact('user', 'subjects'));
    }

I'm not really sure what happened, this upgrade just created a mess I cannot fix.