Skip to content

Instantly share code, notes, and snippets.

@FunctionDJ
Created September 9, 2021 14:53
Show Gist options
  • Save FunctionDJ/b76fcd4692a9837765bffb500eeac973 to your computer and use it in GitHub Desktop.
Save FunctionDJ/b76fcd4692a9837765bffb500eeac973 to your computer and use it in GitHub Desktop.

Revisions

  1. FunctionDJ created this gist Sep 9, 2021.
    14 changes: 14 additions & 0 deletions Example.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <?php

    namespace Database\Seeders;

    use App\Models\ItemProfile;

    class Foo
    {
    public function run(): void
    {
    $profile = ItemProfile::firstOrFail();
    echo $profile->warehouse; // Access to an undefined property (...)
    }
    }
    24 changes: 24 additions & 0 deletions ItemProfile.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    <?php

    namespace App\Models;

    use Illuminate\Database\Eloquent\Factories\HasFactory;
    use Illuminate\Database\Eloquent\Model;

    class ItemProfile extends Model
    {
    use HasFactory;

    protected $casts = [
    "has_batch_number" => "boolean",
    "is_receivable" => "boolean",
    "is_hazardous" => "boolean",
    "has_host_notification" => "boolean",
    "is_deleted" => "boolean"
    ];

    public function item()
    {
    return $this->hasOne(Item::class);
    }
    }