cullymason

cullymason

Member Since 5 Years Ago

Decatur, GA

IT Manager at Connectivity Wireless Solutions

Experience Points 7,330
Experience Level 2

2,670 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 120
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

22 Jun
2 years ago

cullymason left a reply on Polymorphic Relationship Is Not Inserting Type In Database

So, If I wanted to get the User's name that commented, I would say $comment->commentable->name? Right now if I say, $comment->user->name it works and it reads better. Are you sure it looks for the "able" ending?

cullymason started a new conversation Polymorphic Relationship Is Not Inserting Type In Database

In my app, a Comment can be made by either a User or a Contact. In order to set this up, I created a polymorphic relationship between the three models. However, when I try and save the user to the comment, it never inserts the user_type in the database.

Here is what I have for the insert

    $contact = User::where('email',$email->sender)->first();
    $comment->user->attach($contact);

App\Comment


class Comment extends Model
{
    protected $fillable = ['ticket_id','comment','user_id','comment_type_id','user_type'];
    public function user()
    {
        return $this->morphTo();

    }
}

App\User

class User extends Model 
{

    public function comments()
    {
        return $this->morphMany('App\Comment','user');
    }
}

App\Contact

class Contact extends Model 
{

    public function comments()
    {
        return $this->morphMany('App\Comment','user');
    }
}

My comments table looks like this

comments
    - ticket_id
    - comment
    - user_id
    - user_type
    - comment_type_id

Any idea what is going on?

cullymason left a reply on Switching Relationship For Model Based On Field

scratch that. I was over thinking it. Thank you!

cullymason left a reply on Switching Relationship For Model Based On Field

I looked through those and it looks like the morphMany would return all of the "likes" in that example. For mine, the relationship will always only be one to one. Is there an example of a one to one polymorphic relationship?

cullymason started a new conversation Switching Relationship For Model Based On Field

So I have a Model: Comment, that belongs to a "user". The reason the user is in quotes is because depending on the user_type field on the Comment model, the relationship changes to a different model. Here is the code that I have to make that work in the Comment model

public function user() { if($this->user_type="user") { return $this->belongsTo('App\User'); }else{ return $this->belongsTo('App\Contact'); } }

However, when I go to get the user via Comment::find(1)->user, it only works if the user_type is user. In other words, if the user type is contact then the relationship always returns null.

Is it possible to switch the relationship like this? What other information would you need from me to make this more clear?

17 Apr
3 years ago

cullymason started a new conversation Cannot Get Gate To Return True

I am basically trying to set up an ability for a user to open and close a ticket . The logic is pretty simple, if the ticket is owned by the user, then you can open and close it. On a view, I want the Close Ticket button to only show when the ticket can be closed.

here are by abilities defined in the AuthServiceProvider

$gate->define('open-ticket',function($user,$ticket){
            return $user->id===$ticket->owner_id;
        });

$gate->define('close-ticket',function($user,$ticket){
            return $user->id === $ticket->owner_id;
});

In my view, I have

@can('close-ticket',$ticket)
                       <a href="/tickets/{{$ticket->id}}/close" id="close-ticket-button" class="btn btn-danger-outline btn-block">Close Ticket</a>
@endcan

And the button never shows. I have checked the Database to make sure it is true. Then I simply changed the ability so it always returns true like this :

$gate->define('close-ticket',function($user,$ticket){
            return true;
});

And I get the same thing. Any ideas?

19 Oct
3 years ago

cullymason started a new conversation Eager Loading A Relationship With Parent Select Statement

So I have a Ticket model which belongs to a Project model. In the end, I want to select Tickets with certain columns included as well as the project id for each in a collection.

So this works:

    $results = Ticket::get();
    $results->load(['project'=> function($query){
        $query->lists('id');
    }]);
   

Returns:

[{"id":1,"project_id":8,"inoc_id":"31-722761","rfo_code_id":2,"status":"0","customer_affected":0,"severity":"2","notes":"Fuga unde est labore autem tempore beatae iure.","verified":1,"owner":6,"created_at":"2015-10-19 13:46:20","updated_at":"2015-10-19 13:46:20","project":{"id":8}}]

But as soon as I try to select certain columns for a Ticket, the project always comes back null.

    $results = Ticket::select('notes')->get();
    $results->load(['project'=> function($query){
        $query->lists('id');
    }]);
    return $results;
    

[{"notes":"Fuga unde est labore autem tempore beatae iure.","project":null},{"notes":"Enim quia eos dolorum ut.","project":null}]

Any ideas?

10 Feb
4 years ago

cullymason started a new conversation Model::lists() With A Where Clause

Is there a straight forward way to add a constraint when I use the lists() on a Model?

For example

// So return a list of the ids of the projects that are active
Project::lists('id','project_name')->where('project_active','=','1');

04 Oct
4 years ago

cullymason left a reply on Duplicate Environment Variables

I want to use a different database for migrations for the beta site but essentially all of the rest of the environment variables will be the same. I have a dev branch and a master branch. I have two sites set up on forge on a single server, and basically when I push to dev, it publishes to one site and if I push to master it publishes to another.

I have >15 environment variables and I want to make sure I transfer all of them and then change which ones need to be different for the beta site.

cullymason started a new conversation Duplicate Environment Variables

I have a site that I deploy via forge. I want to have a subdomain that I use basically as access to a beta edition for the original main site. Is there a straight forward way that I can copy all of the environment variables from the main site to use for the beta site?

13 Sep
4 years ago

cullymason started a new conversation Whats The Cleanest Way To Add The Active Class To Bootstrap Link Components?

Every method I have ever come up with always seems like a hack. Id like to be able to do something like, if the url matches this pattern then this element is active.