1. Go to this page and download the library: Download emmanuelpcg/laravel-basics 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/ */
emmanuelpcg / laravel-basics example snippets
public function register()
{
BuilderQueries::builderIf();
}
namespace App\QueryFilters\Cars;
use Emmanuelpcg\Basics\QueryFilters\Operators\Equals;
class Color extends Equals { }
namespace App\Repositories;
use App\Models\Car;
use App\QueryFilters\Cars\Color;
use Emmanuelpcg\Basics\Repositories\ModelBasic;
use Illuminate\Database\Eloquent\Model;
class CarsRepository extends ModelBasic
{
protected function getEntityInstance(): Model
{
return new Car();
}
public function paginated(int $perPage)
{
return parent::__pipeApplyFilter(
[Color::class],
$this->getEntityInstance()->query()
)->paginate($perPage);
}
}
namespace App\Repositories;
use App\Models\User;
use App\Repositories\Contracts\IUserRepository;
use Emmanuelpcg\Basics\Repositories\ModelBasic;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
class UserRepository extends ModelBasic implements IUserRepository
{
protected function getEntityInstance(): Model
{
return new User();
}
public function getByEmail(string $email): ?User
{
return parent::__byColumn('email', $email);
}
public function getByKey(int $id): ?User
{
return parent::__byKey($id);
}
public function create(array $data): ?User
{
return parent::__create($data);
}
public function update(int $id, array $data): ?User
{
return parent::__updateByKey($id, $data);
}
// if isset $data['id'] is update if not, is create
public function save(array $data): ?User
{
return parent::__save($data);
}
public function get(): ?Collection
{
return parent::__all();
}
public function getWhereActive(): ?Collection
{
return parent::__allWhere('active', 1);
}
public function delete(int $id): bool
{
return parent::__delete($id);
}
public function getPrimaryKeyName(): string
{
return parent::__getEntityKeyName();
}
}
namespace App\Http\Controllers;
use Emmanuelpcg\Basics\ImageManipulation\ImageManipulation;
use Illuminate\Http\Request;
use Exception;
class UploadsController extends Controller
{
use ImageManipulation;
public function upload(Request $request)
{
try {
return $this->resizeAndSaveImage(
'avatar', // name of field
'avatars', // name of disk
300, // width
300, // height
'user-upload', // new name of image, will be concatenated with timestamp
'png' // format to save
);
} catch (Exception $exception) {
return abort(400, $exception->getMessage());
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.