Below is the code for model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $appends = [
"desc"
];
protected $fillable = ['id'];
public function getDescAttribute()
{
return strip_tags( $this->attributes['description'] );
}
}
So now when i do
$product = Product::first();
It doesn't return desc field in the $product, though when i do $product->desc it returns the result, but i want that result to be appended in the model itself.
The following code gives me error
$product = Product::first()->get(['desc']);
It runs
Select desc from products...
But as the desc is not there i am getting error.
Is anything I'm doing wrong?