protarr

protarr

Member Since 1 Month Ago

Experience Points
730
Total
Experience

4,270 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
4
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 1
730 XP
Oct
13
2 weeks ago
Activity icon

Started a new Conversation How To Get The Foreign Value Of A Relationship Using Eloquent Model::where() ?

How to query the Email model with specific fields AND the name of the user (in another parent table), using one call to Model::where() like this:

$emails = Email::where('user_id', 1)->get(['id','user_id','email']); <- HOW TO ADD THE USER NAME TO THIS LIST?

I know I can retrieve the user name of individual records (using "belongsTo", mentioned below) like $emails[0]->user->name, but I am suposing that exists some way to do this without a loop.

Parent table:

user
    id
    name

Child table:

email
    id
    user_id
    email

On my Email model I have:

    public function user()
    {
        return $this->belongsTo('App\Models\User',  'user_id', 'id');
    }
Oct
05
3 weeks ago
Activity icon

Started a new Conversation How To NOT Return To Previous Route When Session Is Lost (Laravel 8/Jetstream).

Hi. I am using Laravel 8 with Jetstream (god, why) for the first time.

When session is lost and I authenticate again, I return to the route I were before the session was lost. What I want is to avoid this behaviour. After session lost and log in again, I need to be sent to a specific route (like '/', or HOME, for instance).

Activity icon

Replied to How To Execute Arbitrary Code ONCE, Only After The User Logs In.

@michaloravec

I implemented your solution and it worked flawlessly. I will left here how I made it in case someone in the future needs it:

First I discovered that Laravel already have an event called Illuminate\Auth\Events\Login. This event only happens when the user successfully authenticates.

So I create an event listener like this:

$ php artisan make:listener UserLoggedInListener --event='Illuminate\Auth\Events\Login'

Then I registered the event and my listener on EventServiceProvider.php like this:

    protected $listen = [
        Login::class => [
            UserLoggedInListener::class,
        ]
    ];

And inside my listener UserLoggedInListener.php I put:

public function handle(Login $event)
{
    session(['my_variable' => 'my_value']);
}

Now I can access this variable anywhere the session is available: session()->get('my_variable').

Thank you very much.

Oct
04
3 weeks ago
Activity icon

Replied to How To Execute Arbitrary Code ONCE, Only After The User Logs In.

Thank you. I forgot to mention I am using the new laravel jetstream for authentication. Description updated.

Activity icon

Replied to How To Execute Arbitrary Code ONCE, Only After The User Logs In.

The session example isn't important. I just need to run something ONCE, just after the user logs in.

Activity icon

Started a new Conversation How To Execute Arbitrary Code ONCE, Only After The User Logs In.

Laravel 8, using Jetstream

I need to store a variable into the session after the user logs in. The point is: How to do this once?

Currently I am setting this variable value when the user hits the home page, but when the user return to home page the variable is set again, overriding previous value. I can't put this in config because it's a calculated value.

I don't want to check if this variable exist in session every time the user hits the home page (the first route).

Sep
23
1 month ago
Activity icon

Started a new Conversation Using Laravel's Eloquent Models, How Do I Get A Plain Left Join Result?

I want to avoid accessing the tables directly using the DB class.

Let's supose I have these 2 related tables.

user
  id
  name
  age
  
email
  id
  user_id
  email

I created a hasMany emails method on User model, so I can get the emails like: User::find(1)->emails. That's ok and it's working.

But what I really need in this example is to get some users and his respective emails in a plain collection or array, and I need the users that haven't emails too.

I could do User::where('age', 30)->get(), iterate over it and get the User::emails, but this approach isn't nice.

How to achieve this result, using Eloquent models, in a single list, like:

select 
  u.name,
  u.id as user_id,
  e.id as email_id,
  e.email
from user u
left join email e on u.id = e.user_id and u.age = 30
name   user_id    email_id    email
Jack   1          1           [email protected]
Jack   1          2           [email protected]
Anne   2          3           [email protected]
John   3          null        null
Karen  4          null        null

So, in this example, I need all users with age 30, even if they haven't any emails. And I need the result in a plain list as this query would return me.

Thank you.

Activity icon

Started a new Conversation Traverse Models In Multiple Levels Using Laravel's Eloquent

I am using Laravel 8.

Suppose we have 3 tables. table_a, table_b and table_c.

A simple 3 levels of tables. Table A has many B and table B has many C.

table_a
  id
  name
  
table_b
  id
  table_a_id
  name
  
table_c
  id
  table_b_id
  name

I configured in TableA model a method tableB pointing to TableB model using hasMany. It works. I can retrieve the table_b records just using TableA::find(1)->tableB .

I configured in TableB model a method tableC pointing to TableC model using hasMany. It works. I can retrieve the table_c records just using TableB::find(1)->tableC .

Can I retrieve in one step all table_c records related to a table_a record ?

e.g.

Something like TableA::find(1)->... (i need the related records in table_c)

Thank you.