dmcglone27

dmcglone27

Member Since 4 Years Ago

Experience Points
51,900
Total
Experience

3,100 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
487
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 11
51,900 XP
Oct
23
3 days ago
Activity icon

Started a new Conversation Very Frusturating

Can't delete the post so I'll just say solved.

Oct
22
4 days ago
Activity icon

Replied to Is There A Better Way?

Thank you I appreciate it :-)

Activity icon

Replied to Is There A Better Way?

I got it.. take() and limit() both work, I was paying attention to a < div > that I was expecting to also not render and didn't realize the content from the db was working as expected. Learning the Laravel way is gonna be the death of me. lol

Activity icon

Replied to Is There A Better Way?

I only want the section which consist of the maximum of 3 events to show only if there are events present. Otherwise don't show anything. When I do

$events = Event::take(3)->get(); 

I get an sql error.

Activity icon

Started a new Conversation Is There A Better Way?

I think this is horrible... Can anyone recommend a better way to write this?

 public function index()
    {

        $events = Event::all();
        foreach ($events as $event){
            if (!empty($event))
            {
                $events = Event::take(3)->get();

            }
    }

Oct
14
1 week ago
Activity icon

Replied to Form Partial Suggestion

@gvdspuy fixed.... it was so simple, i'm embarrassed. Thanks again!

Activity icon

Replied to Form Partial Suggestion

Thank you @gvdspuy that is a great idea. Using the controller never crossed my mind.

Activity icon

Started a new Conversation Form Partial Suggestion

I hope this makes sense. I have 2 forms that are exactly the same except for the select. I am want to condense both forms into a partial and use it for both the meeting location and the event location. Could this be changed to automatically adapt to which form is being used?

{!! Form::label('Location', 'Location:') !!}</i>
{!! Form::select('locations_id', $meetings, null, array('class'=>'form-control')) !!}


{!! Form::label('Location', 'Location:') !!}</i>
{!! Form::select('locations_id', $events, null, array('class'=>'form-control')) !!}

Sep
29
3 weeks ago
Activity icon

Replied to To Pivot Or Not To Pivot

@tray2 that makes good sense and a good way to think about it.

Activity icon

Replied to To Pivot Or Not To Pivot

@jlrdw Thanks. I'll check it out tomorrow.

Sep
28
4 weeks ago
Activity icon

Started a new Conversation To Pivot Or Not To Pivot

I'm working on understanding relationships and I can't find any good explanations on belongsToMany, hasMany, hasOne etc...

lets say for example if a user hasMany events but an event can belongToMany users or a user hasMany meetings and a meeting can have many organizers do I put the user_id in the event table or the meeting table or should I create a pivot table?

Does anyone know of any good episodes on laracast or youtube that might clear this up a little for me?

Sep
23
1 month ago
Activity icon

Replied to Why The Change In Laravel 8

That's awesome. All in all it doesn't look like too much of a change to adapt to.

Activity icon

Replied to Why The Change In Laravel 8

Even though you have already adapted and stand behind it, have you noticed any drawbacks.

Sep
22
1 month ago
Activity icon

Replied to Why The Change In Laravel 8

True. It'll probably be easier to just adapt.

Activity icon

Replied to Why The Change In Laravel 8

True. I just grabbed 8 to play around with it and get a better understanding. I hope this new way isn't hard to adapt to and proves to be a better way. At least for me, because I'm still fairly new to Laravel and changes like these always mess me up a little.

Activity icon

Replied to Why The Change In Laravel 8

@sinnbeck It seems I was correct about muddying the controllers. In the old way it only takes 3 lines of code. In the new way it takes 5 lines so if my thinking is correct, the only benefit is being able to move controllers to other locations easily. Correct?

Activity icon

Replied to Why The Change In Laravel 8

Ah Hah! Ok I see now.. So instead of a route for every method in a controller, this method just grabs them all with 1 statement.

Am I thinking about that correctly?

Activity icon

Replied to Why The Change In Laravel 8

@sinnbeck that article makes sense. I like the idea. What bothers me is a site could have hundreds of routes, and it seems this method will make the routes file very muddy.

Am I thinking about this wrong?

Activity icon

Started a new Conversation Why The Change In Laravel 8

Why did the method to register routes change in Laravel 8?

Does it make things better? I feel like it only complicated things more.

Sep
12
1 month ago
Activity icon

Replied to Why Does This Seed Fail?

No role was created... So my hunch was correct, but I forgot I could move my Roles table up in the Database seeder in order to have it seeded first.. Now everything is working.

Thank you guys. Much appreciated. :-)

$this->call(RolesTableSeeder::class);
$this->call(UsersTableSeeder::class);
$this->call(EventsTableSeeder::class);
Activity icon

Started a new Conversation Why Does This Seed Fail?

When I try and assign a role to a user when using a database seed It fails. My hunch is this is trying to run before the roles table is seeded. How can I fix this?

Seed


$user = User::create(['id' => '1', 'name' => 'David McGlone', 'email' => '[email protected]', 'password' => 'pass']);
$user->roles()->sync([1,2]);

Error

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`harvest`.`role_user`, CONSTRAINT `role_user_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE) (SQL: insert into `role_user` (`role_id`, `user_id`) values (1, 2))

But when I let a factory do it like so, it works.

$users = factory(App\User::class,20)->create();
$roles = factory(App\Role::class,20)->create();

$users->first()->roles()->sync($roles);


Sep
07
1 month ago
Activity icon

Replied to More Table Confusion

Ah Ok. That does make much better sense. I'll do that.

Activity icon

Replied to More Table Confusion

If I'm following you correctly, what you mean is I should rename the relationship from $event to $user?

Sep
06
1 month ago
Activity icon

Replied to More Table Confusion

I don't know who to give the best answer to, because all 3 of you helped me realize my errors and got my train of thought in the right place.

Maybe the "best answer" should be a many-to-many relationship, because y'all rocked this one. :-)

Activity icon

Replied to More Table Confusion

Sorry guys, I just got home from Church.

I just looked into the first suggestions after replying to Snapey and It works. The problem seems to have been a combination of typo's and my relationship in my model was wrong. Here's the code.

My Model.

 public function user()
    {
        return $this->belongsTo('App\User');

    }

My Controller

   public function show($id)
    {
        $events = Event::with('user')->findOrFail($id);
        return view('pages.events.show', compact( 'events'));
    }

My View

{{$events->user->name}}

I'd like to ask.. Why is it if I change 'user' to 'users' in all 3 places, it fails? What am I missing?

Activity icon

Replied to More Table Confusion

I started out with the idea an event would be able to have more than 1 user.

Then I changed it a couple times, trying to figure out what's going on... Now it feels like a jumbled up mess. and I'm confused.

I've looked for examples and cant' find any. I'm thinking there's a video by Jeff that covers this, but I don't know which one, because the video I was using to learn called "Roles and Abilities" doesn't go that far.

One good thing though, I probably watched that video 100,000 times in the last 2 weeks and I got really good with Tinker. lol

Sep
05
1 month ago
Activity icon

Replied to More Table Confusion

It probably looks strange because it's wrong.. 😂

Activity icon

Replied to More Table Confusion

My bad, I copied the tinker and changed it to hopefully eliminate confusion with what I'm trying to explain. I'll fix that.

Activity icon

Started a new Conversation More Table Confusion

Learning how to retrieve data from db tables has been the biggest challenge for me. I'm not referring the simple default way.

Here I have a table of events, and I have no problem displaying everything in the table, but I want to also display the user who is associated with that event, but I'm thrown off by the id. I can get all the users, but not the user associated with the event with the id of 1. Also I can't use a foreach to loop over the data as we did in my previous question because this isn't an array.

So here's my index method. This is easy. I understand every bit of this code.

public function index()
    {
        $users = User::with('events')->get();

        return view('pages.events.index', compact( 'users'));
    }

But my head explodes when I get to the show method where I am trying to display the user associated with the event..

I have tried a several different ways that don't work. I'll copy my show method of each attempt individually below. but first I want to post output of tinker to show that the relationship is there, I just don't know how to write it.

>>> $user = User::find(1);
=> App\User {#4139
     id: 1,
     name: "David McGlone",
     email: "[email protected]",
     : null,
     img: null,
     created_at: "2020-09-04 17:50:47",
     updated_at: "2020-09-04 17:50:47",
   }
>>> $user->events
=> Illuminate\Database\Eloquent\Collection {#4137
     all: [
       App\Event {#4138
         id: 1,
         user_id: null,
         title: "First Event",
         date: "2008-11-01 00:00:00",
         description: "Organized by david User id - 1",
         location: "Home",
         remember_token: null,
         created_at: "2020-09-04 17:50:47",
         updated_at: "2020-09-04 17:50:47",
         pivot: Illuminate\Database\Eloquent\Relations\Pivot {#4135
           user_id: 1,
           event_id: 1,
         },
       },
     ],
   }
>>> 

Event.php

public function events{

$this->hasMany('App\Event')

}

I found that this grabs the user, BUT it's grabbing the user with the same id as the event.

public function show($id)
    {       
        $events = Event::with('users')->findOrFail($id);

        var_dump($events);     
    }

Same as above.

public function show($id)
    {       
        $events = Event::with('users')->findOrFail($id)->get();

        var_dump($events);     
    }

I can't remember what this did, but i'm sure the experiences ones can see it was wrong.

public function show($id)
    {       
        $events = Event::findOrFail($id);
        $users = User::with('events')->get($id);
  
        return view('pages.events.show', compact( 'events', 'users'));
    }

Sep
04
1 month ago
Activity icon

Replied to No Results With This Query.

Yeah. Let me figure out how to do that.

Activity icon

Replied to No Results With This Query.

Awesome, thank you.

Sep
03
1 month ago
Activity icon

Replied to No Results With This Query.

Thanks that's the first time I've seen 'loop'.

I did not know I had to loop over the roles as well. And I have no idea why it didn't come to mind. I'm working along with one of Jeff's videos and this is what I did just to shake things up for some practice. This was a lesson learned and I'm happy. :-)

@foreach($user->roles as $role)
    @if($role->name != 'members')
  {{ $role->name  }}
@endif
@endforeach
Activity icon

Replied to No Results With This Query.

Hmmmm I didn't see any post where I had written that code. First time I seen that code was in @snapey's example.

I do understand the code when I write it.

Activity icon

Replied to No Results With This Query.

I kinda though that, but I thought the first foreach would do it.

What does this do?

@if(!$loop->last)

Activity icon

Replied to No Results With This Query.

I said oops because I forgot to post my blade code. :-/

I used all those suggestions and still only get 1 role result. For example I have the role of 'admin' and 'creator' but in the blade I only get 'admin'.

I've used

@foreach($users as $user)
{{ $user->roles   }}
@endforeach

And I've used

@foreach($users as $user)
{{ $user->roles->first()->name   }}
@endforeach

Either way, I still only get 1 result.

Activity icon

Replied to No Results With This Query.

Oops.

@foreach($users as $user)
{{ $user->roles   }}

@endforeach
Activity icon

Replied to No Results With This Query.

@snapey It seems I may have confused myself when writing this. I solved part of the problem above, but On the show page I am looking to display each role a user has.

This is what I have in my controller at the moment. This works but does not show all the roles a user has if they have multiple roles. It only shows 1 role. Sounds like I need to iterate over the rolls but not sure how.

User Model

public function roles()
    {
        return $this->belongsToMany('App\Role');
    }

Controller


 $users = User::whereHas('roles')->get();


Aug
31
1 month ago
Activity icon

Replied to No Results With This Query.

I was looking to get only the users who have a role. I am able to do that, but it doesn't display the output correctly. I'm looking for output like so

''' Name: David Role: Edit '''

Instead I get the array output of the full row.

Aug
30
1 month ago
Activity icon

Replied to No Results With This Query.

@silencebringer although this works, it only gets one role if the use has multiple roles.

''' $user->roles->first()->name '''

And if I use

''' $user->role

'''

I get nothing at all.

Activity icon

Replied to No Results With This Query.

Thank you @silencebringer the second one worked. :-)

Activity icon

Replied to No Results With This Query.

I need to ask 1 more question. I'm following along with Jeff's Roles video and I'm trying to get the name of a role from the roles table

This returns the whole row

$user->roles

And this

$user->roles->name

returns this error

Property [name] does not exist on this collection instance.

What am I doing wrong?

Aug
29
1 month ago
Activity icon

Replied to No Results With This Query.

Thanks guys, that worked. I thought I had tried that, that's why I ended up asking.

Activity icon

Started a new Conversation No Results With This Query.

What is happening here. I am not getting any results. I've used 2 different queries. using all() works though...

$users = User::where('name', '==', 'David')->firstOrFail();
 
$users = User::where('name', '==', 'David')->get();

Aug
27
1 month ago
Activity icon

Replied to What's Happening Here

Thanks @sinnbeck .That was it.

Aug
26
2 months ago
Activity icon

Started a new Conversation What's Happening Here

I'm practicing using php Tinker while trying to understand Roles and table relationships better and for someone reason I get slightly different behavior with one Model and not the other and the models are virtually the same.

Why does the first one automatically create an Alias, but the second give me an error? Why do I have to actually specify "App\Program" for the Program Model, but not my Abilities Model?

This works by automaticallly Aliasing Ability to 'App\Ability'.


>>> $adit = Ability::firstOrCreate(['name' => 'editForum']);
[!] Aliasing 'Ability' to 'App\Ability' for this Tinker session.
=> App\Ability {#4120
     name: "editForum",
     updated_at: "2020-08-27 03:20:54",
     created_at: "2020-08-27 03:20:54",
     id: 1,
   }

This will not work.

>>> $christmas = Program::firstOrCreate(['name' => 'Christmas'])

PHP Fatal error:  Class 'Program' not found in Psy Shell code on line 1

This works..


>>> $christmas = App\Program::firstOrCreate(['name' => 'Christmas'])
=> App\Program {#4131
     id: 1,
     name: "Christmas",
     description: null,
     created_at: "2020-08-27 02:25:35",
     updated_at: "2020-08-27 02:25:35",
   }

Aug
23
2 months ago
Activity icon

Started a new Conversation Youtube Video Exceeded

I'm working with the youtube API and I have been refreshing a lot and I've got this once before and had to wait it out. Is there a remedy for this so this doesn't happen?

Error 403 The request cannot be completed because you have exceeded your <a href="/youtube/v3/getting-started#quota">quota</a>. : quotaExceeded

Aug
20
2 months ago
Activity icon

Replied to Can't Seed My Db's

Thanks man I appreciate it :-)

Activity icon

Replied to Can't Seed My Db's

Ok I found the problem and migrations work now.

in UsersTableSeeder I removed

       User::truncate();
       DB::table('role_user')->truncate();

In the RolesTableSeeder I removed


Role::truncate();

From what I understand, this isn't good practice. How should I redo this to make sure it's done correct?

Activity icon

Replied to Can't Seed My Db's

Ok dummy me. I found my seeds and I think I realized my misunderstanding.

Activity icon

Replied to Can't Seed My Db's

Oh boy.

I run the seeds using

php artisan db::seed