composer require nelexa/zip
public function getDownloadAllPassport($passports)
{
$passports = explode(',', $passports);
$name = uniqid();
$zipFile = \PhpZip\ZipOutputFile::create();
foreach ($passports as $passport) {
$user_name = VisaOrder::findOrFail($passport)->name;
if (Upload::getFiles('passport', $user_name)) {
$recursive = true;
$toZipPath = $name . '/';
$zipFile->addDir("upload/passport/$user_name", $recursive, $toZipPath);
}
}
$zipFile->outputAsAttachment('passport.zip');
}
public function scopeFilter($query, $parameters = []){
$fields = ['visa_type', 'status', 'company'];
$filter = collect([
'visa_type' => null,
'status' => null,
'company' => null,
'paginate' => 40,
'order' => 'id',
'sort' => 'desc'
])->merge($parameters);
if (!Auth::user()->hasRole('administrator|Manager')) {
$query->where('user_id', Auth::user()->id);
}
foreach($filter->only($fields) as $field => $value){
$query->where($field, $value);
}
return $query
->orderBy($filter->get('order'), $filter->get('sort'))
->paginate($filter->get('paginate'))
->toArray()['data'];
}
SomeModel::where(...)->filter([
'visa_type' => '....',
'paginate' => 20,
'sort' => 'asc'
]);
if ($visa_type && $status & $company) {
public static function filter($visa_type, $status, $company)
{
$query = self::query();
if (!Auth::user()->hasRole('administrator|Manager')) {
$query->where('user_id', Auth::user()->id);
}
if ($visa_type) {
$query->where('visa_type', $visa_type);
}
if ($status) {
$query->where('status', $visa_type);
}
if ($company) {
$query->where('company', $company);
}
return $query
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
$dataProvider = new self(); //вот этот момент надо проверить
if ($visa_type) {
$dataProvider->where('visa_type', $visa_type);
}
if ($status) {
$dataProvider->where('status', $status);
}
...
return $dataProvider->orderBy('id', 'desc')
->paginate(40)
->toArray()['data']
<?php
namespace App\Http\Requests\User;
use App\Models\User;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Foundation\Http\FormRequest;
class DestroyRequest extends FormRequest
{
public function authorize(Gate $gate)
{
$id = $this->route()->getParameter('user');
return $gate->authorize('destroy', User::query()->findOrFail($id));
}
public function rules()
{
return [
];
}
}
<?php
namespace App\Http\Controllers\Api;
use App\Contracts\IUsersService;
use App\Http\Controllers\Controller;
use App\Http\Requests\User\DestroyRequest;
use App\Http\Requests\User\IndexRequest;
class UsersController extends Controller
{
public function destroy(DestroyRequest $request, $id)
{
// do stuff
}
}
<?php
namespace App\Policies;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class UserPolicy
{
use HandlesAuthorization;
public function index()
{
return true;
}
/**
* rbac:user.destroy
*/
public function destroy(User $user, User $entity)
{
if ($entity->hasRole(User::ROLE_ROOT)) {
return false;
}
return $user->isEditor();
}
}
Какие CMS движки для созданияОборот в корне неверен!
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'https://my-site.com/'),
'port' => env('DB_PORT', ''),
'database' => env('DB_DATABASE', 'my_name'),
'username' => env('DB_USERNAME', 'my_name'),
'password' => env('DB_PASSWORD', 'my_pas'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
'mysql2' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'https://my-site2.com/'),
'port' => env('DB_PORT', ''),
'database' => env('DB_DATABASE', 'my_name2'),
'username' => env('DB_USERNAME', 'my_name3'),
'password' => env('DB_PASSWORD', 'my_pas4'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
DB::connection('mysql')->table('...')->get(); // Выбор из первого соединения
DB::connection('mysql2')->table('...')->get(); // Выбор из второго соединения