Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Config/app.php (dodanie providera)
- App\Providers\RepositoryServiceProvider::class,
- // App/providers
- class RepositoryServiceProvider extends ServiceProvider
- {
- public function register()
- {
- $this->app->bind(UserRepository::class, function ($app) {
- return new UserRepository(User::class);
- });
- }
- }
- // App/repository
- class UserRepository
- {
- /** @var User */
- private static $user;
- public function __construct(User $user)
- {
- self::$user = $user;
- }
- public static function getByEmail(string $email)
- {
- return self::$user->where('email', $email)->get();
- }
- }
- // Controller
- UserRepository::getByEmail($request->email);
- // Result -> call function getByEmail on null
Advertisement
Add Comment
Please, Sign In to add comment