iluca89

Member Since 3 Years Ago

Experience Points
320
Total
Experience

4,680 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
0
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.

  • Community Pillar

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

Level 1
320 XP
Mar
11
1 month ago
Activity icon

Replied to Helper File With Function Calls An Accessors

Sure! $format result example is this PB/#document.protocol_number#/#user.code#

The placeholder_decode function has many other rows (I updated the original post with complete code) that will decode the string passed as parameter.

So, in this case I will expect to receive something like this PB/0001/SA

And it works if I comment the line that calls the accessor

$variables['#document.protocol_number_view#'] = $document->protocol_number_view;

Other times I will pass as $placeholder parameter this #document.protocol_number_view# and I need to be decoded calling the accessor. In this case the function placeholder_decode is not called from the accessor but from other part of the code.

So I think it gets error in case the accessor calls the function placeholder_decode that has a call to itself, but it will not gets error in case the function is called elsewhere.

Let me know if you didn't get me :)

Mar
10
1 month ago
Activity icon

Replied to Helper File With Function Calls An Accessors

This is the result of dd($documento) into placeholder_decode() function:

App\Document {#939
  #table: "documents"
  #fillable: array:13 [
    0 => "company_id"
    1 => "date"
    2 => "type"
    3 => "subject"
    4 => "senderable_type"
    5 => "senderable_id"
    6 => "protocol_number"
    7 => "protocol_date"
    8 => "is_reserved"
    9 => "cancelled"
    10 => "created_user_id"
    11 => "updated_user_id"
    12 => "deleted_user_id"
  ]
  #dates: array:3 [
    0 => "date"
    1 => "protocol_date"
    2 => "deleted_at"
  ]
  #appends: array:1 [
    0 => "protocol_number_view"
  ]
  #connection: "mysql"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:17 [
    "id" => 4
    "company_id" => 1
    "date" => "2020-11-03 19:51:14"
    "type" => "E"
    "subject" => "Richiesta Trofeo"
    "senderable_type" => "App\Address"
    "senderable_id" => 18
    "protocol_number" => 10
    "protocol_date" => "2021-03-10 18:45:50"
    "is_reserved" => 0
    "cancelled" => 0
    "created_user_id" => 1
    "updated_user_id" => 1
    "deleted_user_id" => null
    "created_at" => "2020-11-03 19:51:14"
    "updated_at" => "2021-03-10 18:45:50"
    "deleted_at" => null
  ]
  #original: array:17 [
    "id" => 4
    "company_id" => 1
    "date" => "2020-11-03 19:51:14"
    "type" => "E"
    "subject" => "Richiesta Trofeo"
    "senderable_type" => "App\Address"
    "senderable_id" => 18
    "protocol_number" => 10
    "protocol_date" => "2021-03-10 18:45:50"
    "is_reserved" => 0
    "cancelled" => 0
    "created_user_id" => 1
    "updated_user_id" => 1
    "deleted_user_id" => null
    "created_at" => "2020-11-03 19:51:14"
    "updated_at" => "2021-03-10 18:45:50"
    "deleted_at" => null
  ]
  #changes: []
  #casts: []
  #classCastCache: []
  #dateFormat: null
  #dispatchesEvents: []
  #observables: []
  #relations: array:2 [
    "company" => App\Company {#954
      #table: "companies"
      #fillable: array:4 [
        0 => "name"
        1 => "created_user_id"
        2 => "updated_user_id"
        3 => "deleted_user_id"
      ]
      #connection: "mysql"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:8 [
        "id" => 1
        "name" => "Federazione"
        "created_user_id" => null
        "updated_user_id" => null
        "deleted_user_id" => null
        "created_at" => "2020-10-08 18:45:47"
        "updated_at" => "2020-10-08 18:45:47"
        "deleted_at" => null
      ]
      #original: array:8 [
        "id" => 1
        "name" => "Federazione"
        "created_user_id" => null
        "updated_user_id" => null
        "deleted_user_id" => null
        "created_at" => "2020-10-08 18:45:47"
        "updated_at" => "2020-10-08 18:45:47"
        "deleted_at" => null
      ]
      #changes: []
      #casts: []
      #classCastCache: []
      #dates: array:1 [
        0 => "deleted_at"
      ]
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: []
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #guarded: array:1 [
        0 => "*"
      ]
      #forceDeleting: false
    }
    "tags" => Illuminate\Database\Eloquent\Collection {#919
      #items: []
    }
  ]
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [
    0 => "*"
  ]
  #forceDeleting: false
  #queuedTags: []
}

Maybe it can help us to find a solution...

Activity icon

Replied to Helper File With Function Calls An Accessors

Maybe. How do you suggest to solve it?

Activity icon

Replied to Helper File With Function Calls An Accessors

No, I had it already in my code and it doesn’t work…

Activity icon

Replied to Helper File With Function Calls An Accessors

what do you mean?

When I try to access to this accessor from other part of the code, I can use it...

Activity icon

Replied to Helper File With Function Calls An Accessors

This is the error I get:

[2021-03-10 20:27:54] local.ERROR: ErrorException: Undefined property: App\Document::$protocol_number_view in /var/www/protocol/app/helpers.php:15
Activity icon

Started a new Conversation Helper File With Function Calls An Accessors

Hi guys, I have an helper file with my functions accessible from all parts of the project.

In these functions I have one that call an accessor from a model, but I get error when used.

Here the function:

function placeholder_decode($placeholder, $documento)
{
    $variables['#user.code#'] = Auth::user()->code;
    $variables['#document.protocol_number#'] = str_pad($document->protocol_number, 4, "0", STR_PAD_LEFT);
    $variables['#document.address.name#'] = $document->address->name;
    $variables['#document.subject#'] = $document->subject;
    $variables['#document.date#'] = Carbon::createFromFormat("Y-m-d H:i:s", $document->protocol_date)->format("d/m/Y");
    $variables['#document.protocol_number_view#'] = $document->protocol_number_view;
    $variables['#company.name#'] = Auth::user()->company->name;
    
    $string = json_decode(str_replace(array_keys($variables), array_values($variables), $placeholder));

    return $string[0]->value;

}

The accessor is the call to $documento->protocol_number_view.

This is the code of the accessor into model code:

public function getProtocolNumberViewAttribute()
{
    $format = Configuration::select("value")->where("company_id", $this->attributes['company_id'])->where("name", "prot_format")->get();

    if ($this->attributes['protocol_number'] != 0) {
        $number = placeholder_decode($format, $this);
    } else {
        $number = "";
    }
    return $number;
}
Mar
08
1 month ago
Activity icon

Replied to Call Function From Model Accessor

Hi guys I adopted this way:

I created the function into helpers:

function placeholder_decode($placeholder, $document)
{
    $variables['#user.code#'] = Auth::user()->code;
    $variables['#document.protocol_number#'] = str_pad($document->protocol_number, 4, "0", STR_PAD_LEFT);
    $variables['#document.address.name#'] = $document->address->name;
    $variables['#document.subject#'] = $document->subject;
    $variables['#document.date#'] = Carbon::createFromFormat("Y-m-d H:i:s", $document->protocol_date)->format("d/m/Y");
    $variables['#document.protocol_number_view#'] = $document->protocol_number_view;
    $variables['#company.name#'] = Auth::user()->company->name;
 
    $string = json_decode(str_replace(array_keys($variables), array_values($variables), $placeholder));
 
    return $string[0]->value;

 }

I don't like the return way, any suggestions?

An other problem is that the line

$variables['#document.protocol_number_view#'] = $document->protocol_number_view;

call itselft. This return me an error...

Activity icon

Replied to Use Placeholder To Get Value From Models

Hi guys I adopted this way: I created a function to decode my placeholders like this:

function placeholder_decode($placeholder, $document)
{
    $variables['#user.code#'] = Auth::user()->code;
    $variables['#document.protocol_number#'] = str_pad($document->protocol_number, 4, "0", STR_PAD_LEFT);
    $variables['#document.address.name#'] = $document->address->name;
    $variables['#document.subject#'] = $document->subject;
    $variables['#document.date#'] = Carbon::createFromFormat("Y-m-d H:i:s", $document->protocol_date)->format("d/m/Y");
    $variables['#document.protocol_number_view#'] = $document->protocol_number_view;
    $variables['#company.name#'] = Auth::user()->company->name;

    $string = json_decode(str_replace(array_keys($variables), array_values($variables), $placeholder));

    return $string[0]->value;

}

I don't like the return way, any suggestions?

An other problem is that the line

$variables['#document.protocol_number_view#'] = $document->protocol_number_view;

call an accessor into document model. This return me an error...

Mar
07
1 month ago
Activity icon

Replied to Call Function From Model Accessor

Let me recap your idea... on new helpers.php file I will write the function placeholder_decode($format).

So I will able to call it in many part of the code (accessor included).

Right?

Activity icon

Replied to Call Function From Model Accessor

Because I need to call it in other places...

Mar
06
1 month ago
Activity icon

Replied to Call Function From Model Accessor

Thanks for your message. I can move it out from the controller but I will use it in other places as well as here, so maybe is better to keep it there?

What do you suggest about the last advice? How caching it?

Thanks :)

Activity icon

Started a new Conversation Call Function From Model Accessor

Hi all!

I set an accessor on my model like this:

public function getProtocolNumberViewAttribute()
{
    $format = Configuration::select("value")->where("company_id",$this->attributes['company_id'])->where("name","prot_format")->get();
    $year = Carbon::parse($this->protocol_date)->format('Y');
    $number = $this->createdUser->code . "/" . $this->attributes['protocol_number'] . "-" . $year;
    return $number;
}

As you can see, I set the $number variable in that way. I would set it dinamically based on a value got from database:

$format = Configuration::select("value")->where("company_id", $this->attributes['company_id'])->where("name", "prot_format")->get();

To do this I need to call a function to decode the string I get from database.

I stored this function on the controller. How can I call this function from the controller into the accessor? I tried this code but I got error:

Configuration::placeholder_decode($format)
Activity icon

Replied to Use Placeholder To Get Value From Models

Hi! Suppose I can extract them from the string.

Example from this string PB/[[document.protocol_number]]/[[user.code]] I can extract document.protocol_number with regex/replace or others...

How can convert the string I got to the respective model to get data?

Mar
05
1 month ago
Activity icon

Replied to Use Placeholder To Get Value From Models

I'm using blade but these placeholders are stored in a DB because customer can create its own string.

Activity icon

Started a new Conversation Use Placeholder To Get Value From Models

I would to use placeholder system to get values from database.

Suppose I have this string:

PB/[[document.protocol_number]]/[[user.code]]

I need to replace placeholders inside [[ and ]] with correspondence on models.

For example:

[[document.protocol_number]]

I expect to get protocol_number column from model document.

Do you know already exits something to do this job? Any ideas?

Thanks a lot!