nemrut

nemrut

Member Since 4 Months Ago

Taipei

Experience Points 700
Experience Level 1

4,300 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 1
Lessons
Completed
Best Reply Awards 1
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.

21 Apr
1 month ago

nemrut left a reply on Trying To Get Property Of Non-object

why you loop into single $user ? and are you trying to get firstname of customer or user? because you set costumer to the $user variable. So seems like your customer doesn't has a firstname attribute. try,

public function viewAssessment() {
        $user = Auth::user();
        $pdf = \PDF::loadView('print', compact('user'));
        return $pdf->stream('invoice.pdf');
}

and in view

<ul>
    <li>{{ $user->firstname }}</li>
    //or if trying to get user's customer's name
    <li>{{ $user->customer->firstname }}</li>
</ul>
20 Apr
1 month ago

nemrut left a reply on How To Pass Parameters To Model's Boot() Method

@FTIERSCH - Right, I just noticed, and corrected

trait HasSlug
{
    public static function bootHasSlug()
    {
        static::saving(function ($model) {
            $model->slug = str_slug($model->{$model->slugAttribute});
        });
    }
}

Thank you.

nemrut left a reply on How To Pass Parameters To Model's Boot() Method

i manage to find a nicer way i guess.

trait HasSlug
{
    public static function boot()
    {
        parent::boot();
        static::saving(function ($model) {
            $model->slug = str_slug($model->slugAttribute);
        });
    }
}

in model

class Service extends Model
{
    use HasTranslate,
        HasSlug;

    public $translatable = ['name', 'description'];
    public $slugAttribute = 'name';
...

I was trying to access $slugAttribute from boot method but somehow couldn't. Finally can access it like so.

nemrut left a reply on App Deployed. Yea! So Happens If I Add New Column To User Db

your way is a long way, just make new migration for the existing table as example

php artisan make:migration add_age_to_users_table

edit your new migration as your need

Schema::table('users', function (Blueprint $table) {
    $table->integer('age')->nullable(); //nullable because by default existing users doesn't has any value for the age column
});

then simply migrate

php artisan migrate

your users table will have the new 'age' column and no data will be erased

nemrut left a reply on How To Pass Parameters To Model's Boot() Method

i could manage to make it work in the trait by changing like so:

trait HasSlug
{

    public static function boot()
    {
        parent::boot();

        static::saving(function ($model) {
            $model->slug = str_slug($model->{self::$slugName});
        });
    }
}

and in the model defining $slugName as static property



class Service extends Model
{
    use HasTranslate,
        HasSlug;

    public $translatable = ['name', 'description'];

    public static $slugName = 'name';
....

Not sure if this is proper way but so far it's works. I wanted to ask here if there is anything Laravel specific, as you mention that could add a bootHasSlug method but that will be static as well, so i guess will be the same result. what you think?

nemrut started a new conversation How To Pass Parameters To Model's Boot() Method

Hi, i am trying to make a dynamic slug trait so i can use on all of my sluggable models. For now i am checking via hardcoding without passing any data from model and just checking as:

namespace App\Traits;

trait HasSlug
{

    public static function boot()
    {
        parent::boot();

        static::saving(function ($model) {
            $slugName = $model->title;
            if (!$model->title) {
                $slugName = $model->name;
            }
            $model->slug = str_slug($slugName);
        });
    }
}

what i would like to do is make the slugName variable pass from model as:

class Service extends Model
{
    use HasTranslate,
        HasSlug;

    public $translatable = ['name', 'description'];

    public $slugName = 'name';

    public function works()
    {
        return $this->belongsToMany(Work::class);
    }
}

and use it in the boot method. But i can't figure out how static methods works. Could you give me some suggestions? thanks