PHP code example of nathanbarrett / laravel-repositories

1. Go to this page and download the library: Download nathanbarrett/laravel-repositories library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nathanbarrett / laravel-repositories example snippets


use NathanBarrett\LaravelRepositories\Repository;
use App\Models\User;

/**
* @extends Repository<User>
 */
class UserRepository extends Repository
{
    public function modelClass(): string
    {
        return User::class;
    }
}


class UserController extends Controller
{
    public function __construct(private UserRepository $userRepository)
    {
       //
    }

    public function store(Request $request)
    {
        // The IDE will understand that $user is an instance of User
        $user = $this->userRepository->create($request->all());
        return response()->json($user);
    }
}
bash
php artisan make:repository UserRepository