1. Go to this page and download the library: Download arafat69/laravel-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/ */
arafat69 / laravel-repository example snippets
php artisan make:repository UserRepository
or
// use scope for specific model
php artisan make:repository UserRepository --model=User
//Create
public static function storeByRequest($request): User
{
return self::create([
'first_name' => $request->first_name,
'last_name' => $request->last_name,
'email' => $request->email,
// ...
]);
}
// Update
public static function updateByRequest($request, User $user): User
{
self::update($user, [
'first_name' => $request->first_name,
'last_name' => $request->last_name,
'email' => $request->email,
// ...
]);
// or
$user->update([
// your update data
])
return $user;
}
// etc...
//example UserRepository
use App\Repositories\UserRepository;
// get all user
UserRepository::getAll(); //retun all users
// filter user use query
UserRepository::query()->whereName('jon')->get();
// store method call
UserRepository::storeByRequest($request);
// update method call
UserRepository::updateByRequest($request, $user);
//find
UserRepository::find($userID);
//get first recode
UserRepository::first();
// delete recode
UserRepository::delete($userID);
sh
php artisan vendor:publish --tag=stubs
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.