PHP code example of kamarkoding / kamarkoding-repository
1. Go to this page and download the library: Download kamarkoding/kamarkoding-repository 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/ */
kamarkoding / kamarkoding-repository example snippets
namespace App\Repository\Eloquent;
use App\Repository\Contracts\UserRepositoryInterface;
class UserRepository implements UserRepositoryInterface
{
//
}
josn
namespace App\Http\Controllers;
use App\Repository\Contracts\UserRepositoryInterface;
class UserController extends Controller
{
protected $Users;
public function __construct(UserRepositoryInterface $Users)
{
$this->Users = $Users;
}
public function index()
{
$data = $this->Users->getAll(); // contoh method
return view('Users.index', compact('data'));
}
}
josn
use Livewire\Component;
use App\Repository\Contracts\UserRepositoryInterface;
protected UserRepositoryInterface $userRepository;
class UserIndex extends Component
{
public UserRepositoryInterface $Users;
/**
* Inject repository langsung dari container.
*/
public function mount(UserRepositoryInterface $userRepository)
{
$this->userRepository = $userRepository;
}
public function delete($id)
{
$this->Users->delete($id);
}
public function render()
{
return view('livewire.user.index');
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.