-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b093f6a
commit 315bc17
Showing
10 changed files
with
413 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Exports\ACLs; | ||
|
||
use Spatie\Permission\Contracts\Permission as PermissionModel; | ||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; | ||
use Maatwebsite\Excel\Concerns\ShouldAutoSize; | ||
use Maatwebsite\Excel\Concerns\WithStyles; | ||
use Maatwebsite\Excel\Concerns\WithHeadings; | ||
use Maatwebsite\Excel\Concerns\FromCollection; | ||
|
||
class PermissionExport implements FromCollection, ShouldAutoSize, WithStyles, WithHeadings | ||
{ | ||
/** | ||
* @param \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $sheet | ||
* @return array | ||
*/ | ||
public function styles(Worksheet $sheet) | ||
{ | ||
return [ | ||
|
||
1 => [ "font" => [ "bold" => true, ], ], | ||
]; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function headings(): array | ||
{ | ||
return [ | ||
|
||
"Name", | ||
]; | ||
} | ||
|
||
/** | ||
* @return \Illuminate\Database\Eloquent\Collection | ||
*/ | ||
public function collection() | ||
{ | ||
return app(PermissionModel::class)->all([ | ||
|
||
"name", | ||
]); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Exports\ACLs; | ||
|
||
use Spatie\Permission\Contracts\Role as RoleModel; | ||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; | ||
use Maatwebsite\Excel\Concerns\ShouldAutoSize; | ||
use Maatwebsite\Excel\Concerns\WithStyles; | ||
use Maatwebsite\Excel\Concerns\WithHeadings; | ||
use Maatwebsite\Excel\Concerns\FromCollection; | ||
|
||
class RoleExport implements FromCollection, ShouldAutoSize, WithStyles, WithHeadings | ||
{ | ||
/** | ||
* @param \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $sheet | ||
* @return array | ||
*/ | ||
public function styles(Worksheet $sheet) | ||
{ | ||
return [ | ||
|
||
1 => [ "font" => [ "bold" => true, ], ], | ||
]; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function headings(): array | ||
{ | ||
return [ | ||
|
||
"Name", | ||
]; | ||
} | ||
|
||
/** | ||
* @return \Illuminate\Database\Eloquent\Collection | ||
*/ | ||
public function collection() | ||
{ | ||
return app(RoleModel::class)->all([ | ||
|
||
"name", | ||
]); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Imports\ACLs; | ||
|
||
use Tripteki\ACL\Contracts\Repository\Admin\IACLPermissionRepository; | ||
use App\Http\Requests\Admin\ACLs\Permissions\PermissionStoreValidation; | ||
use Maatwebsite\Excel\Concerns\WithStartRow; | ||
use Maatwebsite\Excel\Concerns\ToCollection; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Validator; | ||
|
||
class PermissionImport implements ToCollection, WithStartRow | ||
{ | ||
/** | ||
* @return int | ||
*/ | ||
public function startRow(): int | ||
{ | ||
return 2; | ||
} | ||
|
||
/** | ||
* @param \Illuminate\Support\Collection $rows | ||
* @return void | ||
*/ | ||
protected function validate(Collection $rows) | ||
{ | ||
$validator = (new PermissionStoreValidation())->rules(); | ||
|
||
Validator::make($rows->toArray(), [ | ||
|
||
"*.0" => $validator["permission"], | ||
|
||
])->validate(); | ||
} | ||
|
||
/** | ||
* @param \Illuminate\Support\Collection $rows | ||
* @return void | ||
*/ | ||
public function collection(Collection $rows) | ||
{ | ||
$this->validate($rows); | ||
|
||
$aclPermissionAdminRepository = app(IACLPermissionRepository::class); | ||
|
||
foreach ($rows as $row) { | ||
|
||
$aclPermissionAdminRepository->rule($row[0]); | ||
} | ||
} | ||
}; |
Oops, something went wrong.