I am trying to call a variable in my Models/Images.php which is for a very good reason but cannot.
My variable $langtitle = 'title'.config('app.LANG_COLUMN_CODE');
which I want to use instead of 'title'
within protected $searchable
Here is my whole code:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Http\Controllers\Traits\Search;
class Images extends Model
{
use Search;
protected $guarded = array();
public $timestamps = false;
protected $fillable = [
'title', 'description', 'categories_id', 'metakeywords', 'hash', 'subgroup','subcategories_id'];
protected $searchable = [
'title',
'metakeywords',
'subgroup'
];
public function user() {
return $this->belongsTo('App\Models\User')->first();
}
public function category() {
return $this->belongsTo('App\Models\Categories', 'categories_id');
}
public function subcategories() {
return $this->belongsTo('App\Models\Subcategories', 'subcategories_id');
}
public function tags() {
return $this->hasMany('App\Models\Images', 'metakeywords');
}
}
I get errors like Constant expression contains invalid operations
CodePudding user response:
As $searchable is getting called somewhere, better to use it directly where this $searchable is gettinh called.
See for $this->searchable
and replace with:
$langtitle.",".'subgroup, metakeywords';
Hint: As I can understand, this might be in Search Traits!