-
Hi, I'm creating Blade:stringable in my project, but Blade:stringable cannot apply to multiple class or instance class like this: public function boot()
{
Blade:stringable(function (Model1 $model) {
return $model->invoke();
});
Blade:stringable(function (Model2 $model) {
return $model->invoke();
});
Blade:stringable(function (Model3 $model) {
return $model->invoke();
});
} I think should be: public function boot()
{
Blade:stringable(function (SomeInterfece $model) {
return $model->invoke();
});
// Or
Blade:stringable(SomeInterface::class, function ($model) {
return $model->invoke();
});
} can laravel do it? |
Beta Was this translation helpful? Give feedback.
Answered by
kaozaza2
Nov 17, 2021
Replies: 2 comments 3 replies
-
This looks like a PHP related constraint and not a Laravel one, PHP8 you can use the following type hints
If you dont have access to PHP8 interfaces is the way to go.
|
Beta Was this translation helpful? Give feedback.
2 replies
-
My attemp in last night: protected $nameableClasses = [
Model1::class,
Model2::class,
Model3::class,
];
public function boot()
{
foreach ($this->nameableClasses as $class) {
Blade::stringable($class, function ($object) {
return $object->getName();
}
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
kaozaza2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My attemp in last night: