I have a model called template and field template - when being called it doesn't exist, so how do I create a property or attribute called template when calling it this is being called through ajax. I tried making an accessor but it's not creating the attribute 'template' getTemplateAttribute($value) so I made a with('template') and I can't seem to create the attribute template in my model when being called.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Template extends Model
{
protected $table = 'templates';
protected $fillable = ['title', 'directory', 'filename', 'created_at', 'updated_at'];
public function template() {
$this->attributes['template'] = 'test';
}
}
// and when calling it
public function show(Template $template)
{
$template = Template::findOrFail($template->id)->with('template');
return $template;
}