BadMethodCallException in Laravel-admin after adding accessor to model
After adding a accessor to my model, Laravel-admin shows the above error when creating a post.
BadMethodCallException In ForwardsCalls.php line 71 : Call to undefined method App\Models\Post::coverUrl()
First few line of App\Models\Post.php
:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Post extends Model {
use HasFactory;
protedted function coverUrl(): Attribute
{
return Attribute::make(
get: fn ( $value) => str_replace(' ','%20',$value),
);
}
I've searched for hours, never finding the same case. Suddenly, this solution just came to my mind, and it worked!
Change protedted function coverUrl(): Attribute
to public function coverUrl(): Attribute
.
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。