app/Author.php
use App\Services\Model; final class Author extends Model{ public function __call($name, $arguments) { return call_user_func_array([app(AuthorRepository::class), $name], $arguments); }}
use App\Services\Model; final class Author extends Model{ public function __call($name, $arguments) { return call_user_func_array([app(AuthorRepository::class), $name], $arguments); }}
use App\Author;use Illuminate\Support\Collection;use Illuminate\Support\Str; class AuthorRepository{ public function all(): Collection { return collect([ [ 'nickname' => 'Gummibeer', 'firstname' => 'Tom', 'lastname' => 'Witkowski', 'payment_pointer' => '$ilp.uphold.com/EagWEdJU64mN', 'twitter' => '@devgummibeer', ], ]) ->mapInto(Author::class); } public function find(string $nickname): Author { return $this->all() ->first(fn (Author $author): bool => Str::slug($author->nickname) === Str::slug($nickname)); }}
use App\Repositories\AuthorRepository;use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider{ public function registerRepositories(): void { // $this->app->singleton(AuthorRepository::class); }}