update code
This commit is contained in:
38
README.md
Normal file
38
README.md
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
## Usage
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# Clone this project
|
||||||
|
git clone https://github.com/ThanhSonITNIC/qlvbdh.git
|
||||||
|
|
||||||
|
# Enter the laradock folder
|
||||||
|
cd qlvbdh/laradock
|
||||||
|
|
||||||
|
# Copy file env-example to .env
|
||||||
|
cp env-example .env
|
||||||
|
|
||||||
|
# Build containers
|
||||||
|
docker-compose build nginx mysql phpmyadmin workspace
|
||||||
|
|
||||||
|
# Run containers
|
||||||
|
docker-compose up -d nginx mysql phpmyadmin workspace
|
||||||
|
|
||||||
|
# Enter the workspace
|
||||||
|
docker-compose exec workspace bash
|
||||||
|
|
||||||
|
# Rename file env-example to .env
|
||||||
|
cp .env.example .env
|
||||||
|
|
||||||
|
# Install packages
|
||||||
|
composer install
|
||||||
|
|
||||||
|
# Generate application key
|
||||||
|
php artisan key:generate
|
||||||
|
|
||||||
|
# Migrate database & seeders
|
||||||
|
php artisan migrate:fresh --seed
|
||||||
|
|
||||||
|
# Run the worker
|
||||||
|
php artisan queue:work
|
||||||
|
```
|
||||||
|
|
||||||
|
Open your browser and visit localhost: http://localhost
|
||||||
36
app/Casts/Json.php
Normal file
36
app/Casts/Json.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Casts;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|
||||||
|
class Json implements CastsAttributes
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Cast the given value.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
* @param string $key
|
||||||
|
* @param mixed $value
|
||||||
|
* @param array $attributes
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get($model, $key, $value, $attributes)
|
||||||
|
{
|
||||||
|
return json_decode($value, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare the given value for storage.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
* @param string $key
|
||||||
|
* @param array $value
|
||||||
|
* @param array $attributes
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function set($model, $key, $value, $attributes)
|
||||||
|
{
|
||||||
|
return json_encode($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
41
app/Console/Kernel.php
Normal file
41
app/Console/Kernel.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console;
|
||||||
|
|
||||||
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
|
class Kernel extends ConsoleKernel
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The Artisan commands provided by your application.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $commands = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the application's command schedule.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function schedule(Schedule $schedule)
|
||||||
|
{
|
||||||
|
// $schedule->command('inspire')->hourly();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the commands for the application.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function commands()
|
||||||
|
{
|
||||||
|
$this->load(__DIR__.'/Commands');
|
||||||
|
|
||||||
|
require base_path('routes/console.php');
|
||||||
|
}
|
||||||
|
}
|
||||||
15
app/Contracts/Repositories/AttachmentRepository.php
Normal file
15
app/Contracts/Repositories/AttachmentRepository.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Contracts\Repositories;
|
||||||
|
|
||||||
|
use Prettus\Repository\Contracts\RepositoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface AttachmentRepository.
|
||||||
|
*
|
||||||
|
* @package namespace App\Contracts\Repositories;
|
||||||
|
*/
|
||||||
|
interface AttachmentRepository extends RepositoryInterface
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
15
app/Contracts/Repositories/BookRepository.php
Normal file
15
app/Contracts/Repositories/BookRepository.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Contracts\Repositories;
|
||||||
|
|
||||||
|
use Prettus\Repository\Contracts\RepositoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface BookRepository.
|
||||||
|
*
|
||||||
|
* @package namespace App\Contracts\Repositories;
|
||||||
|
*/
|
||||||
|
interface BookRepository extends RepositoryInterface
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
15
app/Contracts/Repositories/DepartmentRepository.php
Normal file
15
app/Contracts/Repositories/DepartmentRepository.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Contracts\Repositories;
|
||||||
|
|
||||||
|
use Prettus\Repository\Contracts\RepositoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface DepartmentRepository.
|
||||||
|
*
|
||||||
|
* @package namespace App\Contracts\Repositories;
|
||||||
|
*/
|
||||||
|
interface DepartmentRepository extends RepositoryInterface
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
15
app/Contracts/Repositories/DocumentRepository.php
Normal file
15
app/Contracts/Repositories/DocumentRepository.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Contracts\Repositories;
|
||||||
|
|
||||||
|
use Prettus\Repository\Contracts\RepositoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface DocumentRepository.
|
||||||
|
*
|
||||||
|
* @package namespace App\Contracts\Repositories;
|
||||||
|
*/
|
||||||
|
interface DocumentRepository extends RepositoryInterface
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
15
app/Contracts/Repositories/DocumentTypeRepository.php
Normal file
15
app/Contracts/Repositories/DocumentTypeRepository.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Contracts\Repositories;
|
||||||
|
|
||||||
|
use Prettus\Repository\Contracts\RepositoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface DocumentTypeRepository.
|
||||||
|
*
|
||||||
|
* @package namespace App\Contracts\Repositories;
|
||||||
|
*/
|
||||||
|
interface DocumentTypeRepository extends RepositoryInterface
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
15
app/Contracts/Repositories/OrganizeRepository.php
Normal file
15
app/Contracts/Repositories/OrganizeRepository.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Contracts\Repositories;
|
||||||
|
|
||||||
|
use Prettus\Repository\Contracts\RepositoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface OrganizeRepository.
|
||||||
|
*
|
||||||
|
* @package namespace App\Contracts\Repositories;
|
||||||
|
*/
|
||||||
|
interface OrganizeRepository extends RepositoryInterface
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
15
app/Contracts/Repositories/PermissionRepository.php
Normal file
15
app/Contracts/Repositories/PermissionRepository.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Contracts\Repositories;
|
||||||
|
|
||||||
|
use Prettus\Repository\Contracts\RepositoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface PermissionRepository.
|
||||||
|
*
|
||||||
|
* @package namespace App\Contracts\Repositories;
|
||||||
|
*/
|
||||||
|
interface PermissionRepository extends RepositoryInterface
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
15
app/Contracts/Repositories/RoleRepository.php
Normal file
15
app/Contracts/Repositories/RoleRepository.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Contracts\Repositories;
|
||||||
|
|
||||||
|
use Prettus\Repository\Contracts\RepositoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface RoleRepository.
|
||||||
|
*
|
||||||
|
* @package namespace App\Contracts\Repositories;
|
||||||
|
*/
|
||||||
|
interface RoleRepository extends RepositoryInterface
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
15
app/Contracts/Repositories/SignerRepository.php
Normal file
15
app/Contracts/Repositories/SignerRepository.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Contracts\Repositories;
|
||||||
|
|
||||||
|
use Prettus\Repository\Contracts\RepositoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface SignerRepository.
|
||||||
|
*
|
||||||
|
* @package namespace App\Contracts\Repositories;
|
||||||
|
*/
|
||||||
|
interface SignerRepository extends RepositoryInterface
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
15
app/Contracts/Repositories/TitleRepository.php
Normal file
15
app/Contracts/Repositories/TitleRepository.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Contracts\Repositories;
|
||||||
|
|
||||||
|
use Prettus\Repository\Contracts\RepositoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface TitleRepository.
|
||||||
|
*
|
||||||
|
* @package namespace App\Contracts\Repositories;
|
||||||
|
*/
|
||||||
|
interface TitleRepository extends RepositoryInterface
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
15
app/Contracts/Repositories/UserRepository.php
Normal file
15
app/Contracts/Repositories/UserRepository.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Contracts\Repositories;
|
||||||
|
|
||||||
|
use Prettus\Repository\Contracts\RepositoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface UserRepository.
|
||||||
|
*
|
||||||
|
* @package namespace App\Contracts\Repositories;
|
||||||
|
*/
|
||||||
|
interface UserRepository extends RepositoryInterface
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
49
app/Criteria/DocumentCriteria.php
Normal file
49
app/Criteria/DocumentCriteria.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Criteria;
|
||||||
|
|
||||||
|
use Prettus\Repository\Contracts\CriteriaInterface;
|
||||||
|
use Prettus\Repository\Contracts\RepositoryInterface;
|
||||||
|
use App\Entities\Book;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DocumentCriteria.
|
||||||
|
*
|
||||||
|
* @package namespace App\Criteria;
|
||||||
|
*/
|
||||||
|
class DocumentCriteria implements CriteriaInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Apply criteria in query repository
|
||||||
|
*
|
||||||
|
* @param string $model
|
||||||
|
* @param RepositoryInterface $repository
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function apply($model, RepositoryInterface $repository)
|
||||||
|
{
|
||||||
|
$model = $model->where(function($model){
|
||||||
|
$model = $model->where(function($model){
|
||||||
|
if(auth()->user()->hasPermissionTo('Quản lý văn bản đến')){
|
||||||
|
$model->orWhere('book_id', Book::DEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(auth()->user()->hasPermissionTo('Quản lý văn bản đi')){
|
||||||
|
$model->orWhere('book_id', Book::DI);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(auth()->user()->hasPermissionTo('Quản lý văn bản nội bộ')){
|
||||||
|
$model->orWhere('book_id', Book::NOIBO);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$model = $model->orWhere(function($model){
|
||||||
|
$ids = auth()->user()->documents->map->id;
|
||||||
|
$model->orWhereIn('id', $ids);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
}
|
||||||
54
app/Entities/Attachment.php
Normal file
54
app/Entities/Attachment.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entities;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Prettus\Repository\Contracts\Transformable;
|
||||||
|
use Prettus\Repository\Traits\TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Attachment.
|
||||||
|
*
|
||||||
|
* @package namespace App\Entities;
|
||||||
|
*/
|
||||||
|
class Attachment extends Model implements Transformable
|
||||||
|
{
|
||||||
|
use TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'document_id',
|
||||||
|
'name',
|
||||||
|
'extension',
|
||||||
|
'size',
|
||||||
|
'path',
|
||||||
|
'downloads',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All of the relationships to be touched.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $touches = ['document'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be cast to native types.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $casts = [
|
||||||
|
'size' => 'decimal:2',
|
||||||
|
'downloads' => 'integer'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function document(){
|
||||||
|
return $this->belongsTo(Document::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
63
app/Entities/Book.php
Normal file
63
app/Entities/Book.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entities;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Prettus\Repository\Contracts\Transformable;
|
||||||
|
use Prettus\Repository\Traits\TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Book.
|
||||||
|
*
|
||||||
|
* @package namespace App\Entities;
|
||||||
|
*/
|
||||||
|
class Book extends Model implements Transformable
|
||||||
|
{
|
||||||
|
use TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'name'];
|
||||||
|
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
public $appends = ['unread', 'count'];
|
||||||
|
|
||||||
|
public const DI = 2;
|
||||||
|
public const DEN = 1;
|
||||||
|
public const NOIBO = 3;
|
||||||
|
|
||||||
|
public function documents(){
|
||||||
|
return $this->hasMany(Document::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isComeIn(){
|
||||||
|
return $this->id == self::DEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isComeOut(){
|
||||||
|
return $this->id == self::DI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isPrivate(){
|
||||||
|
return $this->id == self::NOIBO;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUnreadAttribute(){
|
||||||
|
return $this->documents()
|
||||||
|
->wherehas('receivers', function($query) {
|
||||||
|
return $query->where('id', auth()->id())->where('seen', false);
|
||||||
|
})->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCountAttribute(){
|
||||||
|
return $this->documents()
|
||||||
|
->wherehas('receivers', function($query) {
|
||||||
|
return $query->where('id', auth()->id());
|
||||||
|
})->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
app/Entities/Department.php
Normal file
35
app/Entities/Department.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entities;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Prettus\Repository\Contracts\Transformable;
|
||||||
|
use Prettus\Repository\Traits\TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Department.
|
||||||
|
*
|
||||||
|
* @package namespace App\Entities;
|
||||||
|
*/
|
||||||
|
class Department extends Model implements Transformable
|
||||||
|
{
|
||||||
|
use TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'name', 'tel'];
|
||||||
|
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
public $incrementing = false;
|
||||||
|
|
||||||
|
protected $keyType = 'string';
|
||||||
|
|
||||||
|
public function users(){
|
||||||
|
return $this->hasMany(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
100
app/Entities/Document.php
Normal file
100
app/Entities/Document.php
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entities;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Prettus\Repository\Contracts\Transformable;
|
||||||
|
use Prettus\Repository\Traits\TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Document.
|
||||||
|
*
|
||||||
|
* @package namespace App\Entities;
|
||||||
|
*/
|
||||||
|
class Document extends Model implements Transformable
|
||||||
|
{
|
||||||
|
use TransformableTrait;
|
||||||
|
use \App\Traits\ActionCallable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'symbol',
|
||||||
|
'abstract',
|
||||||
|
'book_id',
|
||||||
|
'type_id',
|
||||||
|
'signer_id',
|
||||||
|
'sign_at',
|
||||||
|
'creator_id',
|
||||||
|
'writer_id',
|
||||||
|
'effective_at',
|
||||||
|
'publisher_id',
|
||||||
|
'link_id',
|
||||||
|
];
|
||||||
|
|
||||||
|
public $appends = [
|
||||||
|
'seen',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'effective_at' => 'date:Y-m-d',
|
||||||
|
'sign_at' => 'date:Y-m-d',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function receivers(){
|
||||||
|
return $this->belongsToMany(User::class, 'document_receivers')->withPivot(['seen']);;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function organizes(){
|
||||||
|
return $this->belongsToMany(Organize::class, 'document_organizes');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function type(){
|
||||||
|
return $this->belongsTo(DocumentType::class, 'type_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attachments(){
|
||||||
|
return $this->hasMany(Attachment::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function book(){
|
||||||
|
return $this->belongsTo(Book::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function publisher(){
|
||||||
|
return $this->belongsTo(Organize::class, 'publisher_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function signer(){
|
||||||
|
return $this->belongsTo(Signer::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function creator(){
|
||||||
|
return $this->belongsTo(User::class, 'creator_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function writer(){
|
||||||
|
return $this->belongsTo(User::class, 'writer_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function linkTo(){
|
||||||
|
return $this->belongsTo(Document::class, 'link_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function linked(){
|
||||||
|
return $this->hasMany(Document::class, 'link_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSeenAttribute(){
|
||||||
|
$receiver = $this->receivers()->where('id', auth()->id())->first();
|
||||||
|
if($receiver){
|
||||||
|
return $receiver->pivot->seen;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
app/Entities/DocumentType.php
Normal file
35
app/Entities/DocumentType.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entities;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Prettus\Repository\Contracts\Transformable;
|
||||||
|
use Prettus\Repository\Traits\TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DocumentType.
|
||||||
|
*
|
||||||
|
* @package namespace App\Entities;
|
||||||
|
*/
|
||||||
|
class DocumentType extends Model implements Transformable
|
||||||
|
{
|
||||||
|
use TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'name'];
|
||||||
|
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
public $incrementing = false;
|
||||||
|
|
||||||
|
protected $keyType = 'string';
|
||||||
|
|
||||||
|
public function documents(){
|
||||||
|
return $this->hasMany(Documents::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
40
app/Entities/Organize.php
Normal file
40
app/Entities/Organize.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entities;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Prettus\Repository\Contracts\Transformable;
|
||||||
|
use Prettus\Repository\Traits\TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Organize.
|
||||||
|
*
|
||||||
|
* @package namespace App\Entities;
|
||||||
|
*/
|
||||||
|
class Organize extends Model implements Transformable
|
||||||
|
{
|
||||||
|
use TransformableTrait;
|
||||||
|
use \App\Traits\ActionCallable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'name'];
|
||||||
|
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
public $incrementing = false;
|
||||||
|
|
||||||
|
protected $keyType = 'string';
|
||||||
|
|
||||||
|
public function publishedDocuments(){
|
||||||
|
return $this->hasMany(Document::class, 'publisher_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function receivedDocuments(){
|
||||||
|
return $this->belongsToMany(Document::class, 'document_organizes');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
31
app/Entities/Signer.php
Normal file
31
app/Entities/Signer.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entities;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Prettus\Repository\Contracts\Transformable;
|
||||||
|
use Prettus\Repository\Traits\TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Signer.
|
||||||
|
*
|
||||||
|
* @package namespace App\Entities;
|
||||||
|
*/
|
||||||
|
class Signer extends Model implements Transformable
|
||||||
|
{
|
||||||
|
use TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'name', 'description'];
|
||||||
|
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
public function documents(){
|
||||||
|
return $this->hasMany(Document::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
app/Entities/Title.php
Normal file
35
app/Entities/Title.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entities;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Prettus\Repository\Contracts\Transformable;
|
||||||
|
use Prettus\Repository\Traits\TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Title.
|
||||||
|
*
|
||||||
|
* @package namespace App\Entities;
|
||||||
|
*/
|
||||||
|
class Title extends Model implements Transformable
|
||||||
|
{
|
||||||
|
use TransformableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'name'];
|
||||||
|
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
public $incrementing = false;
|
||||||
|
|
||||||
|
protected $keyType = 'string';
|
||||||
|
|
||||||
|
public function users(){
|
||||||
|
return $this->hasMany(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
88
app/Entities/User.php
Normal file
88
app/Entities/User.php
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entities;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
use Laravel\Sanctum\HasApiTokens;
|
||||||
|
use Spatie\Permission\Traits\HasRoles;
|
||||||
|
use Illuminate\Contracts\Auth\CanResetPassword;
|
||||||
|
use Illuminate\Auth\Passwords\CanResetPassword as CanResetPasswordTrait;
|
||||||
|
use Prettus\Repository\Contracts\Transformable;
|
||||||
|
use Prettus\Repository\Traits\TransformableTrait;
|
||||||
|
|
||||||
|
class User extends Authenticatable implements Transformable, CanResetPassword
|
||||||
|
{
|
||||||
|
use HasApiTokens, Notifiable, HasRoles, CanResetPasswordTrait, TransformableTrait;
|
||||||
|
use \App\Traits\ActionCallable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'email',
|
||||||
|
'password',
|
||||||
|
'tel',
|
||||||
|
'birthday',
|
||||||
|
'department_id',
|
||||||
|
'title_id',
|
||||||
|
'active',
|
||||||
|
];
|
||||||
|
|
||||||
|
public $incrementing = false;
|
||||||
|
|
||||||
|
protected $keyType = 'string';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be hidden for arrays.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $hidden = [
|
||||||
|
'password', 'remember_token',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be cast to native types.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $casts = [
|
||||||
|
'email_verified_at' => 'datetime',
|
||||||
|
'active' => 'boolean',
|
||||||
|
'birthday' => 'date:Y-m-d',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function groups(){
|
||||||
|
return $this->belongsToMany(Group::class, GroupUser::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function department(){
|
||||||
|
return $this->belongsTo(Department::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function title(){
|
||||||
|
return $this->belongsTo(Title::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createdDocuments(){
|
||||||
|
return $this->hasMany(Document::class, 'creator_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function wroteDocuments(){
|
||||||
|
return $this->hasMany(Document::class, 'writer_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function receivedDocuments(){
|
||||||
|
return $this->belongsToMany(Document::class, 'document_receivers');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDocumentsAttribute(){
|
||||||
|
return $this->createdDocuments->merge($this->receivedDocuments)->merge($this->wroteDocuments());
|
||||||
|
}
|
||||||
|
}
|
||||||
57
app/Events/ActionCalled.php
Normal file
57
app/Events/ActionCalled.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use Illuminate\Broadcasting\Channel;
|
||||||
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||||
|
use Illuminate\Broadcasting\PresenceChannel;
|
||||||
|
use Illuminate\Broadcasting\PrivateChannel;
|
||||||
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||||
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use App\Entities\Document;
|
||||||
|
use App\Entities\User;
|
||||||
|
|
||||||
|
class ActionCalled
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||||
|
|
||||||
|
public $model;
|
||||||
|
public $action;
|
||||||
|
public $paramIds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($model, string $action, $params = [])
|
||||||
|
{
|
||||||
|
$this->model = $model;
|
||||||
|
$this->action = $action;
|
||||||
|
$this->paramIds = collect($params);
|
||||||
|
$this->paramIds->shift();
|
||||||
|
|
||||||
|
$this->eventsRegister();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function eventsRegister()
|
||||||
|
{
|
||||||
|
if($this->action == 'attach'){
|
||||||
|
if(!$this->paramIds->count()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event(new UsersReceivedDocument($this->model, User::find($this->paramIds)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the channels the event should broadcast on.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Broadcasting\Channel|array
|
||||||
|
*/
|
||||||
|
public function broadcastOn()
|
||||||
|
{
|
||||||
|
return new PrivateChannel('channel-name');
|
||||||
|
}
|
||||||
|
}
|
||||||
39
app/Events/UserViewedDocument.php
Normal file
39
app/Events/UserViewedDocument.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use Illuminate\Broadcasting\Channel;
|
||||||
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||||
|
use Illuminate\Broadcasting\PresenceChannel;
|
||||||
|
use Illuminate\Broadcasting\PrivateChannel;
|
||||||
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||||
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use App\Entities\Document;
|
||||||
|
|
||||||
|
class UserViewedDocument
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||||
|
|
||||||
|
public $document;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Document $document)
|
||||||
|
{
|
||||||
|
$this->document = $document;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the channels the event should broadcast on.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Broadcasting\Channel|array
|
||||||
|
*/
|
||||||
|
public function broadcastOn()
|
||||||
|
{
|
||||||
|
return new PrivateChannel('channel-name');
|
||||||
|
}
|
||||||
|
}
|
||||||
41
app/Events/UsersReceivedDocument.php
Normal file
41
app/Events/UsersReceivedDocument.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use Illuminate\Broadcasting\Channel;
|
||||||
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||||
|
use Illuminate\Broadcasting\PresenceChannel;
|
||||||
|
use Illuminate\Broadcasting\PrivateChannel;
|
||||||
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||||
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use App\Entities\Document;
|
||||||
|
|
||||||
|
class UsersReceivedDocument
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||||
|
|
||||||
|
public $document;
|
||||||
|
public $users;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Document $document, $users)
|
||||||
|
{
|
||||||
|
$this->document = $document;
|
||||||
|
$this->users = $users;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the channels the event should broadcast on.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Broadcasting\Channel|array
|
||||||
|
*/
|
||||||
|
public function broadcastOn()
|
||||||
|
{
|
||||||
|
return new PrivateChannel('channel-name');
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Exceptions/AccountNotActive.php
Normal file
22
app/Exceptions/AccountNotActive.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Prettus\Repository\Traits\Respondable;
|
||||||
|
|
||||||
|
class AccountNotActive extends Exception
|
||||||
|
{
|
||||||
|
use Respondable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the exception into an HTTP response.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function render($request)
|
||||||
|
{
|
||||||
|
return $this->respondError('Account not activated', 403);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Exceptions/ActionNotFound.php
Normal file
22
app/Exceptions/ActionNotFound.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class ActionNotFound extends Exception
|
||||||
|
{
|
||||||
|
use \Prettus\Repository\Traits\Respondable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render an exception into an HTTP response.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Throwable $exception
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function render($request)
|
||||||
|
{
|
||||||
|
return $this->respondError('Action '. $this->getMessage() .' has not been defined.', 422);
|
||||||
|
}
|
||||||
|
}
|
||||||
78
app/Exceptions/Handler.php
Normal file
78
app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
|
use Throwable;
|
||||||
|
use Prettus\Repository\Traits\Respondable;
|
||||||
|
|
||||||
|
class Handler extends ExceptionHandler
|
||||||
|
{
|
||||||
|
use Respondable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of the exception types that are not reported.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $dontReport = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of the inputs that are never flashed for validation exceptions.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $dontFlash = [
|
||||||
|
'password',
|
||||||
|
'password_confirmation',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report or log an exception.
|
||||||
|
*
|
||||||
|
* @param \Throwable $exception
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function report(Throwable $exception)
|
||||||
|
{
|
||||||
|
parent::report($exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render an exception into an HTTP response.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Throwable $exception
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
*
|
||||||
|
* @throws \Throwable
|
||||||
|
*/
|
||||||
|
public function render($request, Throwable $exception)
|
||||||
|
{
|
||||||
|
if($exception instanceof \Illuminate\Database\Eloquent\ModelNotFoundException)
|
||||||
|
{
|
||||||
|
return $this->respondNotFound($exception->getMessage());
|
||||||
|
}
|
||||||
|
elseif($exception instanceof \Illuminate\Database\QueryException)
|
||||||
|
{
|
||||||
|
return $this->respondError($exception->errorInfo, 422);
|
||||||
|
}
|
||||||
|
elseif($exception instanceof \Illuminate\Database\Eloquent\RelationNotFoundException)
|
||||||
|
{
|
||||||
|
return $this->respondError($exception->getMessage(), 422);
|
||||||
|
}
|
||||||
|
elseif($exception instanceof \Prettus\Validator\Exceptions\ValidatorException)
|
||||||
|
{
|
||||||
|
return $this->respondError($exception, 400);
|
||||||
|
}
|
||||||
|
elseif($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException)
|
||||||
|
{
|
||||||
|
return $this->respondNotFound('Url not found');
|
||||||
|
}
|
||||||
|
return parent::render($request, $exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Exceptions/RelationIdsNotAllow.php
Normal file
22
app/Exceptions/RelationIdsNotAllow.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class RelationIdsNotAllow extends Exception
|
||||||
|
{
|
||||||
|
use \Prettus\Repository\Traits\Respondable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render an exception into an HTTP response.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Throwable $exception
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function render($request)
|
||||||
|
{
|
||||||
|
return $this->respondError('The relation id "'. $this->getMessage() .'" not allow.', 405);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Exceptions/RelationNotAllow.php
Normal file
22
app/Exceptions/RelationNotAllow.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class RelationNotAllow extends Exception
|
||||||
|
{
|
||||||
|
use \Prettus\Repository\Traits\Respondable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render an exception into an HTTP response.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Throwable $exception
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function render($request)
|
||||||
|
{
|
||||||
|
return $this->respondError('The relation "'. $this->getMessage() .'" not allow.', 405);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
app/Exceptions/UserIdIncorrectFormat.php
Normal file
29
app/Exceptions/UserIdIncorrectFormat.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Prettus\Repository\Traits\Respondable;
|
||||||
|
use App\Entities\User;
|
||||||
|
|
||||||
|
class UserIdIncorrectFormat extends Exception
|
||||||
|
{
|
||||||
|
use Respondable;
|
||||||
|
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
public function __construct(User $user){
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the exception into an HTTP response.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function render($request)
|
||||||
|
{
|
||||||
|
return $this->respondError("Mã người dùng " . $this->user->id . " không đúng định dạng.", 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
91
app/Exports/BaseDocumentsExport.php
Normal file
91
app/Exports/BaseDocumentsExport.php
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports;
|
||||||
|
|
||||||
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||||
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Color;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Conditional;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithPreCalculateFormulas;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||||
|
use Maatwebsite\Excel\Events\BeforeExport;
|
||||||
|
use Maatwebsite\Excel\Events\BeforeWriting;
|
||||||
|
use Maatwebsite\Excel\Events\BeforeSheet;
|
||||||
|
use Maatwebsite\Excel\Events\AfterSheet;
|
||||||
|
|
||||||
|
abstract class BaseDocumentsExport
|
||||||
|
implements
|
||||||
|
FromCollection,
|
||||||
|
WithHeadings,
|
||||||
|
WithMapping,
|
||||||
|
ShouldAutoSize,
|
||||||
|
WithTitle,
|
||||||
|
WithCustomStartCell,
|
||||||
|
WithColumnFormatting,
|
||||||
|
WithPreCalculateFormulas,
|
||||||
|
WithEvents
|
||||||
|
{
|
||||||
|
protected $documents;
|
||||||
|
protected $title;
|
||||||
|
protected $from;
|
||||||
|
protected $to;
|
||||||
|
|
||||||
|
public function __construct($documents, string $title, $from = null, $to = null){
|
||||||
|
$this->documents = $documents;
|
||||||
|
$this->title = $title;
|
||||||
|
$this->from = $from;
|
||||||
|
$this->to = $to;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
public function collection()
|
||||||
|
{
|
||||||
|
return $this->documents;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function headings(): array;
|
||||||
|
|
||||||
|
abstract public function map($document): array;
|
||||||
|
|
||||||
|
public function title(): string
|
||||||
|
{
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startCell(): string
|
||||||
|
{
|
||||||
|
return 'A1';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function columnFormats(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'A' => NumberFormat::FORMAT_DATE_DDMMYYYY,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerEvents(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
AfterSheet::class => [self::class, 'afterSheet'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function afterSheet(AfterSheet $event)
|
||||||
|
{
|
||||||
|
// $event->getSheet()->getDelegate()->setCellValue('A10', 'xxx');
|
||||||
|
|
||||||
|
// $style = new Color(Color::COLOR_RED);!
|
||||||
|
// $event->getSheet()->getDelegate()->setConditionalStyles('A10', $style);!
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
51
app/Exports/BooksExport.php
Normal file
51
app/Exports/BooksExport.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports;
|
||||||
|
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||||
|
use App\Entities\Book;
|
||||||
|
use App\Exports\{
|
||||||
|
ComeInDocumentsExport,
|
||||||
|
ComeOutDocumentsExport,
|
||||||
|
PrivateDocumentsExport,
|
||||||
|
};
|
||||||
|
|
||||||
|
class BooksExport implements WithMultipleSheets
|
||||||
|
{
|
||||||
|
protected $books;
|
||||||
|
protected $from;
|
||||||
|
protected $to;
|
||||||
|
|
||||||
|
public function __construct($books, $from = null, $to = null){
|
||||||
|
$this->books = $books;
|
||||||
|
$this->from = $from;
|
||||||
|
$this->to = $to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sheets(): array
|
||||||
|
{
|
||||||
|
$sheets = [];
|
||||||
|
|
||||||
|
foreach ($this->books as $book) {
|
||||||
|
$sheets[] = $this->getSheet($book);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sheets;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getSheet(Book $book)
|
||||||
|
{
|
||||||
|
if($book->isComeIn()){
|
||||||
|
return new ComeInDocumentsExport($book->documents, $book->name, $this->from, $this->to);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($book->isComeOut()){
|
||||||
|
return new ComeOutDocumentsExport($book->documents, $book->name, $this->from, $this->to);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($book->isPrivate()){
|
||||||
|
return new PrivateDocumentsExport($book->documents, $book->name, $this->from, $this->to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
app/Exports/ComeInDocumentsExport.php
Normal file
35
app/Exports/ComeInDocumentsExport.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||||
|
|
||||||
|
class ComeInDocumentsExport extends BaseDocumentsExport
|
||||||
|
{
|
||||||
|
public function headings(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'Ngày nhận',
|
||||||
|
'Nơi ban hành',
|
||||||
|
'Ký hiệu',
|
||||||
|
'Loại',
|
||||||
|
'Trích yếu',
|
||||||
|
'Người nhận',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($document): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Date::dateTimeToExcel($document->effective_at),
|
||||||
|
$document->publisher->name,
|
||||||
|
$document->symbol,
|
||||||
|
$document->type->name,
|
||||||
|
$document->abstract,
|
||||||
|
implode(', ', ($document->receivers->map(function($receiver){
|
||||||
|
return $receiver->name;
|
||||||
|
}))->toArray()),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
38
app/Exports/ComeOutDocumentsExport.php
Normal file
38
app/Exports/ComeOutDocumentsExport.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||||
|
|
||||||
|
class ComeOutDocumentsExport extends BaseDocumentsExport
|
||||||
|
{
|
||||||
|
public function headings(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'Ngày ban hành',
|
||||||
|
'Ký hiệu',
|
||||||
|
'Loại',
|
||||||
|
'Trích yếu',
|
||||||
|
'Nơi nhận',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $document
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function map($document): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Date::dateTimeToExcel($document->effective_at),
|
||||||
|
$document->symbol,
|
||||||
|
$document->type->name,
|
||||||
|
$document->abstract,
|
||||||
|
implode(', ', ($document->organizes->map(function($organize){
|
||||||
|
return $organize->name;
|
||||||
|
}))->toArray()),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
38
app/Exports/PrivateDocumentsExport.php
Normal file
38
app/Exports/PrivateDocumentsExport.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||||
|
|
||||||
|
class PrivateDocumentsExport extends BaseDocumentsExport
|
||||||
|
{
|
||||||
|
public function headings(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'Ngày ban hành',
|
||||||
|
'Ký hiệu',
|
||||||
|
'Loại',
|
||||||
|
'Trích yếu',
|
||||||
|
'Người nhận',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $document
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function map($document): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Date::dateTimeToExcel($document->effective_at),
|
||||||
|
$document->symbol,
|
||||||
|
$document->type->name,
|
||||||
|
$document->abstract,
|
||||||
|
implode(', ', ($document->organizes->map(function($organize){
|
||||||
|
return $organize->name;
|
||||||
|
}))->toArray()),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
81
app/Exports/UsersExport.php
Normal file
81
app/Exports/UsersExport.php
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports;
|
||||||
|
|
||||||
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||||
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Color;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Conditional;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithPreCalculateFormulas;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||||
|
use Maatwebsite\Excel\Events\BeforeExport;
|
||||||
|
use Maatwebsite\Excel\Events\BeforeWriting;
|
||||||
|
use Maatwebsite\Excel\Events\BeforeSheet;
|
||||||
|
use Maatwebsite\Excel\Events\AfterSheet;
|
||||||
|
|
||||||
|
class UsersExport
|
||||||
|
implements
|
||||||
|
FromCollection,
|
||||||
|
WithHeadings,
|
||||||
|
WithMapping,
|
||||||
|
ShouldAutoSize,
|
||||||
|
WithTitle,
|
||||||
|
WithCustomStartCell
|
||||||
|
{
|
||||||
|
protected $users;
|
||||||
|
|
||||||
|
public function __construct($users){
|
||||||
|
$this->users = $users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function collection()
|
||||||
|
{
|
||||||
|
return $this->users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function headings(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'Mã',
|
||||||
|
'Tên',
|
||||||
|
'Email',
|
||||||
|
'Số điện thoại',
|
||||||
|
'Ngày sinh',
|
||||||
|
'Chức danh',
|
||||||
|
'Phòng ban',
|
||||||
|
'Kích hoạt',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($user): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
$user->id,
|
||||||
|
$user->name,
|
||||||
|
$user->email,
|
||||||
|
$user->tel,
|
||||||
|
explode(' ', $user->birthday)[0],
|
||||||
|
$user->title_id,
|
||||||
|
$user->department_id,
|
||||||
|
$user->active,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function title(): string
|
||||||
|
{
|
||||||
|
return 'Danh sách người dùng';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startCell(): string
|
||||||
|
{
|
||||||
|
return 'A1';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
45
app/Fakers/AbstractDocumentFacker.php
Normal file
45
app/Fakers/AbstractDocumentFacker.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Fakers;
|
||||||
|
|
||||||
|
use Faker\Provider\Base;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use App\Entities\Book;
|
||||||
|
use App\Entities\DocumentType;
|
||||||
|
use App\Entities\User;
|
||||||
|
use App\Entities\Signer;
|
||||||
|
use App\Entities\Organize;
|
||||||
|
|
||||||
|
class AbstractDocumentFacker extends Base
|
||||||
|
{
|
||||||
|
public function document()
|
||||||
|
{
|
||||||
|
$response = Http::get('https://vanbanphapluat.co/api/search');
|
||||||
|
|
||||||
|
$items = $response->json()['Items'];
|
||||||
|
$num = count($items);
|
||||||
|
|
||||||
|
$id = random_int(0, $num - 1);
|
||||||
|
|
||||||
|
return $this->map($items[$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function map(array $attributes)
|
||||||
|
{
|
||||||
|
$pHCHCUsers = User::where('department_id', 'PHCHC')->get();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'symbol' => $attributes['SoHieu'],
|
||||||
|
'abstract' => $attributes['TrichYeu'],
|
||||||
|
'book_id' => Book::all()->random()->id,
|
||||||
|
'type_id' => DocumentType::all()->random()->id,
|
||||||
|
'signer_id' => Signer::all()->random()->id,
|
||||||
|
'creator_id' => $pHCHCUsers->first() ? $pHCHCUsers->random()->id : 1,
|
||||||
|
'effective_at' => date_create($attributes['NgayBanHanh'] ?? "now"),
|
||||||
|
'sign_at' => date_create($attributes['NgayHieuLuc'] ?? "now"),
|
||||||
|
'publisher_id' => Organize::all()->random()->id,
|
||||||
|
'writer_id' => $pHCHCUsers->first() ? $pHCHCUsers->random()->id : 1,
|
||||||
|
'link_id' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
119
app/Http/Controllers/Api/AttachmentsController.php
Normal file
119
app/Http/Controllers/Api/AttachmentsController.php
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Contracts\Repositories\AttachmentRepository;
|
||||||
|
use App\Http\Requests\Attachment\{
|
||||||
|
IndexRequest,
|
||||||
|
CreateRequest,
|
||||||
|
ShowRequest,
|
||||||
|
UpdateRequest,
|
||||||
|
DestroyRequest,
|
||||||
|
};
|
||||||
|
use App\Traits\Attachmentable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AttachmentsController.
|
||||||
|
*
|
||||||
|
* @package namespace App\Http\Controllers\Api;
|
||||||
|
*/
|
||||||
|
class AttachmentsController extends Controller
|
||||||
|
{
|
||||||
|
use Attachmentable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var AttachmentRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AttachmentsController constructor.
|
||||||
|
*
|
||||||
|
* @param AttachmentRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(AttachmentRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index(IndexRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->all();
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\CreateRequest $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(CreateRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->attachment($request->file('attachments'), $request->document_id);
|
||||||
|
return $this->respondCreated($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
|
||||||
|
* @param $CLASS\ShowRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show(ShowRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->find($id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download attachment
|
||||||
|
* @param $CLASS\ShowRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function download(ShowRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->find($id);
|
||||||
|
return $this->downloadAttachment($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\UpdateRequest $request
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->update($request->all(), $id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\DestroyRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy(DestroyRequest $request, $id)
|
||||||
|
{
|
||||||
|
$this->removeAttachment($this->repository->find($id));
|
||||||
|
$this->repository->delete($id);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
102
app/Http/Controllers/Api/BooksController.php
Normal file
102
app/Http/Controllers/Api/BooksController.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Contracts\Repositories\BookRepository;
|
||||||
|
use App\Http\Requests\Book\{
|
||||||
|
IndexRequest,
|
||||||
|
CreateRequest,
|
||||||
|
ShowRequest,
|
||||||
|
UpdateRequest,
|
||||||
|
DestroyRequest,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class BooksController.
|
||||||
|
*
|
||||||
|
* @package namespace App\Http\Controllers\Api;
|
||||||
|
*/
|
||||||
|
class BooksController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var BookRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BooksController constructor.
|
||||||
|
*
|
||||||
|
* @param BookRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(BookRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index(IndexRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->all();
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\CreateRequest $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(CreateRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->create($request->all());
|
||||||
|
return $this->respondCreated($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
|
||||||
|
* @param $CLASS\ShowRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show(ShowRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->find($id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\UpdateRequest $request
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->update($request->all(), $id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\DestroyRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy(DestroyRequest $request, $id)
|
||||||
|
{
|
||||||
|
$this->repository->delete($id);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
102
app/Http/Controllers/Api/DepartmentsController.php
Normal file
102
app/Http/Controllers/Api/DepartmentsController.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Contracts\Repositories\DepartmentRepository;
|
||||||
|
use App\Http\Requests\Department\{
|
||||||
|
IndexRequest,
|
||||||
|
CreateRequest,
|
||||||
|
ShowRequest,
|
||||||
|
UpdateRequest,
|
||||||
|
DestroyRequest,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DepartmentsController.
|
||||||
|
*
|
||||||
|
* @package namespace App\Http\Controllers\Api;
|
||||||
|
*/
|
||||||
|
class DepartmentsController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var DepartmentRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DepartmentsController constructor.
|
||||||
|
*
|
||||||
|
* @param DepartmentRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(DepartmentRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index(IndexRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->all();
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\CreateRequest $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(CreateRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->create($request->all());
|
||||||
|
return $this->respondCreated($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
|
||||||
|
* @param $CLASS\ShowRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show(ShowRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->find($id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\UpdateRequest $request
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->update($request->all(), $id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\DestroyRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy(DestroyRequest $request, $id)
|
||||||
|
{
|
||||||
|
$this->repository->delete($id);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
102
app/Http/Controllers/Api/DocumentTypesController.php
Normal file
102
app/Http/Controllers/Api/DocumentTypesController.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Contracts\Repositories\DocumentTypeRepository;
|
||||||
|
use App\Http\Requests\DocumentType\{
|
||||||
|
IndexRequest,
|
||||||
|
CreateRequest,
|
||||||
|
ShowRequest,
|
||||||
|
UpdateRequest,
|
||||||
|
DestroyRequest,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DocumentTypesController.
|
||||||
|
*
|
||||||
|
* @package namespace App\Http\Controllers\Api;
|
||||||
|
*/
|
||||||
|
class DocumentTypesController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var DocumentTypeRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DocumentTypesController constructor.
|
||||||
|
*
|
||||||
|
* @param DocumentTypeRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(DocumentTypeRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index(IndexRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->all();
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\CreateRequest $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(CreateRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->create($request->all());
|
||||||
|
return $this->respondCreated($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
|
||||||
|
* @param $CLASS\ShowRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show(ShowRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->find($id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\UpdateRequest $request
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->update($request->all(), $id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\DestroyRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy(DestroyRequest $request, $id)
|
||||||
|
{
|
||||||
|
$this->repository->delete($id);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
110
app/Http/Controllers/Api/DocumentsController.php
Normal file
110
app/Http/Controllers/Api/DocumentsController.php
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Contracts\Repositories\DocumentRepository;
|
||||||
|
use App\Http\Requests\Document\{
|
||||||
|
IndexRequest,
|
||||||
|
CreateRequest,
|
||||||
|
ShowRequest,
|
||||||
|
UpdateRequest,
|
||||||
|
DestroyRequest,
|
||||||
|
};
|
||||||
|
use App\Traits\Attachmentable;
|
||||||
|
use App\Events\UserViewedDocument;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DocumentsController.
|
||||||
|
*
|
||||||
|
* @package namespace App\Http\Controllers\Api;
|
||||||
|
*/
|
||||||
|
class DocumentsController extends Controller
|
||||||
|
{
|
||||||
|
use Attachmentable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DocumentRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DocumentsController constructor.
|
||||||
|
*
|
||||||
|
* @param DocumentRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(DocumentRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index(IndexRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->paginate();
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\CreateRequest $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(CreateRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->create($request->all());
|
||||||
|
if($request->filled('attachments')){
|
||||||
|
$this->attachments($request->file('attachments'), $data->id);
|
||||||
|
}
|
||||||
|
return $this->respondCreated($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
|
||||||
|
* @param $CLASS\ShowRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show(ShowRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->find($id);
|
||||||
|
event(new UserViewedDocument($data));
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\UpdateRequest $request
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->gateAction($this->repository, $request, $id) ?: $this->repository->update($request->except('creator_id'), $id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\DestroyRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy(DestroyRequest $request, $id)
|
||||||
|
{
|
||||||
|
$this->repository->delete($id);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
66
app/Http/Controllers/Api/MeController.php
Normal file
66
app/Http/Controllers/Api/MeController.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Contracts\Repositories\UserRepository;
|
||||||
|
use App\Http\Requests\Me\{
|
||||||
|
ShowRequest,
|
||||||
|
UpdateRequest,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class MeController.
|
||||||
|
*
|
||||||
|
* @package namespace App\Http\Controllers\Api;
|
||||||
|
*/
|
||||||
|
class MeController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var UserRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MeController constructor.
|
||||||
|
*
|
||||||
|
* @param UserRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(UserRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
|
||||||
|
* @param $CLASS\ShowRequest $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show(ShowRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->find($request->user()->id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\UpdateRequest $request
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request)
|
||||||
|
{
|
||||||
|
if($request->filled('password')){
|
||||||
|
$request->password = \Hash::make($request->password);
|
||||||
|
}
|
||||||
|
$data = $this->repository->update(
|
||||||
|
$request->except(['department_id', 'title_id', 'active', 'id']),
|
||||||
|
$request->user()->id
|
||||||
|
);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
91
app/Http/Controllers/Api/NotificationsController.php
Normal file
91
app/Http/Controllers/Api/NotificationsController.php
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class NotificationsController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get all notifications
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$data = request()->user()->notifications;
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get read notifications
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function read()
|
||||||
|
{
|
||||||
|
$data = request()->user()->readNotifications;
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get unread notifications
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function unread()
|
||||||
|
{
|
||||||
|
$data = request()->user()->unreadNotifications;
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark all as read
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function markAllAsRead()
|
||||||
|
{
|
||||||
|
request()->user()->unreadNotifications->markAsRead();
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark as read
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function markAsRead($id)
|
||||||
|
{
|
||||||
|
$data = request()->user()->notifications->where('id', $id)->first();
|
||||||
|
$data->markAsRead();
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark as unread
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function markAsUnread($id)
|
||||||
|
{
|
||||||
|
$data = request()->user()->notifications->where('id', $id)->first();
|
||||||
|
$data->markAsUnread();
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
request()->user()->notifications->where('id', $id)->first()->delete();
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
102
app/Http/Controllers/Api/OrganizesController.php
Normal file
102
app/Http/Controllers/Api/OrganizesController.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Contracts\Repositories\OrganizeRepository;
|
||||||
|
use App\Http\Requests\Organize\{
|
||||||
|
IndexRequest,
|
||||||
|
CreateRequest,
|
||||||
|
ShowRequest,
|
||||||
|
UpdateRequest,
|
||||||
|
DestroyRequest,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class OrganizesController.
|
||||||
|
*
|
||||||
|
* @package namespace App\Http\Controllers\Api;
|
||||||
|
*/
|
||||||
|
class OrganizesController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OrganizeRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OrganizesController constructor.
|
||||||
|
*
|
||||||
|
* @param OrganizeRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(OrganizeRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index(IndexRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->all();
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\CreateRequest $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(CreateRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->create($request->all());
|
||||||
|
return $this->respondCreated($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
|
||||||
|
* @param $CLASS\ShowRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show(ShowRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->find($id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\UpdateRequest $request
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->update($request->all(), $id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\DestroyRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy(DestroyRequest $request, $id)
|
||||||
|
{
|
||||||
|
$this->repository->delete($id);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
102
app/Http/Controllers/Api/PermissionsController.php
Normal file
102
app/Http/Controllers/Api/PermissionsController.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Contracts\Repositories\PermissionRepository;
|
||||||
|
use App\Http\Requests\Permission\{
|
||||||
|
IndexRequest,
|
||||||
|
CreateRequest,
|
||||||
|
ShowRequest,
|
||||||
|
UpdateRequest,
|
||||||
|
DestroyRequest,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PermissionsController.
|
||||||
|
*
|
||||||
|
* @package namespace App\Http\Controllers\Api;
|
||||||
|
*/
|
||||||
|
class PermissionsController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var PermissionRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PermissionsController constructor.
|
||||||
|
*
|
||||||
|
* @param PermissionRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(PermissionRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index(IndexRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->all();
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\CreateRequest $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(CreateRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->create($request->all());
|
||||||
|
return $this->respondCreated($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
|
||||||
|
* @param $CLASS\ShowRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show(ShowRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->find($id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\UpdateRequest $request
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->update($request->all(), $id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\DestroyRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy(DestroyRequest $request, $id)
|
||||||
|
{
|
||||||
|
$this->repository->delete($id);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
86
app/Http/Controllers/Api/ReportsController.php
Normal file
86
app/Http/Controllers/Api/ReportsController.php
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Contracts\Repositories\DocumentRepository;
|
||||||
|
use App\Contracts\Repositories\BookRepository;
|
||||||
|
use App\Http\Requests\Document\{
|
||||||
|
ExportRequest,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ReportsController.
|
||||||
|
*
|
||||||
|
* @package namespace App\Http\Controllers\Api;
|
||||||
|
*/
|
||||||
|
class ReportsController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var DocumentRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var BookRepository
|
||||||
|
*/
|
||||||
|
protected $bookRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ReportsController constructor.
|
||||||
|
*
|
||||||
|
* @param DocumentRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(DocumentRepository $repository, BookRepository $bookRepository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
$this->bookRepository = $bookRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download report
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function export(ExportRequest $request)
|
||||||
|
{
|
||||||
|
$books = $this->bookRepository->all();
|
||||||
|
|
||||||
|
if($request->filled('book')){
|
||||||
|
$books = collect();
|
||||||
|
$books->push($this->bookRepository->find($request->book));
|
||||||
|
}
|
||||||
|
|
||||||
|
$books->map(function ($book) use ($request)
|
||||||
|
{
|
||||||
|
$documents = $this->repository->scopeQuery(function($query) use ($request, $book)
|
||||||
|
{
|
||||||
|
$query->where('book_id', $book->id);
|
||||||
|
|
||||||
|
if($request->filled('type')){
|
||||||
|
$query->where('type_id', $request->type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($request->filled('from')){
|
||||||
|
$request->to = $request->to ?: date('Y-m-d');
|
||||||
|
$query->whereBetween('effective_at', [$request->from, $request->to]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query
|
||||||
|
->with(['receivers', 'publisher', 'organizes'])
|
||||||
|
->orderBy('effective_at')
|
||||||
|
->orderBy('publisher_id');
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
})->all();
|
||||||
|
|
||||||
|
return $book->documents = $documents;
|
||||||
|
});
|
||||||
|
|
||||||
|
$name = auth()->user()->name . ' ' . date('d-m-Y');
|
||||||
|
$fileName = $name . '.' . strtolower($request->export);
|
||||||
|
$exporter = new \App\Exports\BooksExport($books, $request->from, $request->to);
|
||||||
|
return \Excel::download($exporter, $fileName, $request->export);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
114
app/Http/Controllers/Api/RolesController.php
Normal file
114
app/Http/Controllers/Api/RolesController.php
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Contracts\Repositories\RoleRepository;
|
||||||
|
use App\Http\Requests\Role\{
|
||||||
|
IndexRequest,
|
||||||
|
CreateRequest,
|
||||||
|
ShowRequest,
|
||||||
|
UpdateRequest,
|
||||||
|
DestroyRequest,
|
||||||
|
GivePermissionRequest,
|
||||||
|
RevokePermissionRequest,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class RolesController.
|
||||||
|
*
|
||||||
|
* @package namespace App\Http\Controllers\Api;
|
||||||
|
*/
|
||||||
|
class RolesController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var RoleRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RolesController constructor.
|
||||||
|
*
|
||||||
|
* @param RoleRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(RoleRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index(IndexRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->all();
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\CreateRequest $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(CreateRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->create($request->all());
|
||||||
|
return $this->respondCreated($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
|
||||||
|
* @param $CLASS\ShowRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show(ShowRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->find($id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\UpdateRequest $request
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->update($request->all(), $id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\DestroyRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy(DestroyRequest $request, $id)
|
||||||
|
{
|
||||||
|
$this->repository->delete($id);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function givePermission(GivePermissionRequest $request, $role, $permission){
|
||||||
|
$this->repository->find($role)->givePermissionTo($permission);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function revokePermission(RevokePermissionRequest $request, $role, $permission){
|
||||||
|
$this->repository->find($role)->revokePermissionTo($permission);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
102
app/Http/Controllers/Api/SignersController.php
Normal file
102
app/Http/Controllers/Api/SignersController.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Contracts\Repositories\SignerRepository;
|
||||||
|
use App\Http\Requests\Signer\{
|
||||||
|
IndexRequest,
|
||||||
|
CreateRequest,
|
||||||
|
ShowRequest,
|
||||||
|
UpdateRequest,
|
||||||
|
DestroyRequest,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class SignersController.
|
||||||
|
*
|
||||||
|
* @package namespace App\Http\Controllers\Api;
|
||||||
|
*/
|
||||||
|
class SignersController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var SignerRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SignersController constructor.
|
||||||
|
*
|
||||||
|
* @param SignerRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(SignerRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index(IndexRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->all();
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\CreateRequest $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(CreateRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->create($request->all());
|
||||||
|
return $this->respondCreated($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
|
||||||
|
* @param $CLASS\ShowRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show(ShowRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->find($id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\UpdateRequest $request
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->update($request->all(), $id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\DestroyRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy(DestroyRequest $request, $id)
|
||||||
|
{
|
||||||
|
$this->repository->delete($id);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
102
app/Http/Controllers/Api/TitlesController.php
Normal file
102
app/Http/Controllers/Api/TitlesController.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Contracts\Repositories\TitleRepository;
|
||||||
|
use App\Http\Requests\Title\{
|
||||||
|
IndexRequest,
|
||||||
|
CreateRequest,
|
||||||
|
ShowRequest,
|
||||||
|
UpdateRequest,
|
||||||
|
DestroyRequest,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class TitlesController.
|
||||||
|
*
|
||||||
|
* @package namespace App\Http\Controllers\Api;
|
||||||
|
*/
|
||||||
|
class TitlesController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var TitleRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TitlesController constructor.
|
||||||
|
*
|
||||||
|
* @param TitleRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(TitleRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index(IndexRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->all();
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\CreateRequest $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(CreateRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->create($request->all());
|
||||||
|
return $this->respondCreated($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
|
||||||
|
* @param $CLASS\ShowRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show(ShowRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->find($id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\UpdateRequest $request
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->update($request->all(), $id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\DestroyRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy(DestroyRequest $request, $id)
|
||||||
|
{
|
||||||
|
$this->repository->delete($id);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
145
app/Http/Controllers/Api/UsersController.php
Normal file
145
app/Http/Controllers/Api/UsersController.php
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Contracts\Repositories\UserRepository;
|
||||||
|
use App\Http\Requests\User\{
|
||||||
|
IndexRequest,
|
||||||
|
CreateRequest,
|
||||||
|
ShowRequest,
|
||||||
|
UpdateRequest,
|
||||||
|
DestroyRequest,
|
||||||
|
GiveRoleRequest,
|
||||||
|
GivePermissionRequest,
|
||||||
|
ExportRequest,
|
||||||
|
ImportRequest,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class UsersController.
|
||||||
|
*
|
||||||
|
* @package namespace App\Http\Controllers\Api;
|
||||||
|
*/
|
||||||
|
class UsersController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var UserRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UsersController constructor.
|
||||||
|
*
|
||||||
|
* @param UserRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(UserRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index(IndexRequest $request)
|
||||||
|
{
|
||||||
|
$data = $this->repository->paginate();
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\CreateRequest $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(CreateRequest $request)
|
||||||
|
{
|
||||||
|
$request->merge(['password' => \Hash::make($request->password)]);
|
||||||
|
$data = $this->repository->create($request->all());
|
||||||
|
return $this->respondCreated($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
|
||||||
|
* @param $CLASS\ShowRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show(ShowRequest $request, $id)
|
||||||
|
{
|
||||||
|
$data = $this->repository->find($id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\UpdateRequest $request
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, $id)
|
||||||
|
{
|
||||||
|
if($request->filled('password')){
|
||||||
|
$request->password = \Hash::make($request->password);
|
||||||
|
}
|
||||||
|
$data = $this->repository->update($request->all(), $id);
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param $CLASS\DestroyRequest $request
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy(DestroyRequest $request, $id)
|
||||||
|
{
|
||||||
|
$this->repository->delete($id);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function giveRole(GiveRoleRequest $request, $user, $role){
|
||||||
|
$this->repository->find($user)->assignRole($role);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function revokeRole(GiveRoleRequest $request, $user, $role){
|
||||||
|
$this->repository->find($user)->removeRole($role);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function givePermission(GiveRoleRequest $request, $user, $permission){
|
||||||
|
$this->repository->find($user)->givePermissionTo($permission);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function revokePermission(GiveRoleRequest $request, $user, $permission){
|
||||||
|
$this->repository->find($user)->revokePermissionTo($permission);
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function import(ImportRequest $request)
|
||||||
|
{
|
||||||
|
\Excel::import(new \App\Imports\UsersImport, $request->file('data'));
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function export(ExportRequest $request)
|
||||||
|
{
|
||||||
|
$users = $this->repository->all();
|
||||||
|
$exporter = new \App\Exports\UsersExport($users);
|
||||||
|
$fileName = 'Danh sách người dùng.' . $request->export;
|
||||||
|
return \Excel::download($exporter, $fileName, $request->export);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
40
app/Http/Controllers/Auth/ConfirmPasswordController.php
Normal file
40
app/Http/Controllers/Auth/ConfirmPasswordController.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use Illuminate\Foundation\Auth\ConfirmsPasswords;
|
||||||
|
|
||||||
|
class ConfirmPasswordController extends Controller
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Confirm Password Controller
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This controller is responsible for handling password confirmations and
|
||||||
|
| uses a simple trait to include the behavior. You're free to explore
|
||||||
|
| this trait and override any functions that require customization.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use ConfirmsPasswords;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where to redirect users when the intended url fails.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $redirectTo = RouteServiceProvider::HOME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new controller instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware('auth');
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal file
22
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||||
|
|
||||||
|
class ForgotPasswordController extends Controller
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Password Reset Controller
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This controller is responsible for handling password reset emails and
|
||||||
|
| includes a trait which assists in sending these notifications from
|
||||||
|
| your application to your users. Feel free to explore this trait.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use SendsPasswordResetEmails;
|
||||||
|
}
|
||||||
63
app/Http/Controllers/Auth/LoginController.php
Normal file
63
app/Http/Controllers/Auth/LoginController.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use \Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class LoginController extends Controller
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Login Controller
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This controller handles authenticating users for the application and
|
||||||
|
| redirecting them to your home screen. The controller uses a trait
|
||||||
|
| to conveniently provide its functionality to your applications.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use AuthenticatesUsers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where to redirect users after login.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $redirectTo = RouteServiceProvider::HOME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new controller instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware('guest')->except('logout');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function guard()
|
||||||
|
{
|
||||||
|
return Auth::guard('web');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the needed authorization credentials from the request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function credentials(Request $request)
|
||||||
|
{
|
||||||
|
if(filter_var($request->email, FILTER_VALIDATE_EMAIL)){
|
||||||
|
return $request->only($this->username(), 'password');
|
||||||
|
}
|
||||||
|
$request->merge(['id' => $request->email]);
|
||||||
|
return $request->only('id', 'password');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
73
app/Http/Controllers/Auth/RegisterController.php
Normal file
73
app/Http/Controllers/Auth/RegisterController.php
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use App\User;
|
||||||
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
|
class RegisterController extends Controller
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Register Controller
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This controller handles the registration of new users as well as their
|
||||||
|
| validation and creation. By default this controller uses a trait to
|
||||||
|
| provide this functionality without requiring any additional code.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use RegistersUsers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where to redirect users after registration.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $redirectTo = RouteServiceProvider::HOME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new controller instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware('guest');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a validator for an incoming registration request.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return \Illuminate\Contracts\Validation\Validator
|
||||||
|
*/
|
||||||
|
protected function validator(array $data)
|
||||||
|
{
|
||||||
|
return Validator::make($data, [
|
||||||
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||||
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new user instance after a valid registration.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return \App\User
|
||||||
|
*/
|
||||||
|
protected function create(array $data)
|
||||||
|
{
|
||||||
|
return User::create([
|
||||||
|
'name' => $data['name'],
|
||||||
|
'email' => $data['email'],
|
||||||
|
'password' => Hash::make($data['password']),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
62
app/Http/Controllers/Auth/ResetPasswordController.php
Normal file
62
app/Http/Controllers/Auth/ResetPasswordController.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Auth\Events\PasswordReset;
|
||||||
|
|
||||||
|
class ResetPasswordController extends Controller
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Password Reset Controller
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This controller is responsible for handling password reset requests
|
||||||
|
| and uses a simple trait to include this behavior. You're free to
|
||||||
|
| explore this trait and override any methods you wish to tweak.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use ResetsPasswords;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where to redirect users after resetting their password.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $redirectTo = RouteServiceProvider::HOME;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the response for a successful password reset.
|
||||||
|
*
|
||||||
|
* @param $request
|
||||||
|
* @param string $response
|
||||||
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
protected function sendResetResponse($request, $response)
|
||||||
|
{
|
||||||
|
return $this->respondNoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the given user's password.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Contracts\Auth\CanResetPassword $user
|
||||||
|
* @param string $password
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected function resetPassword($user, $password)
|
||||||
|
{
|
||||||
|
$this->setUserPassword($user, $password);
|
||||||
|
$user->setRememberToken(Str::random(60));
|
||||||
|
$user->save();
|
||||||
|
event(new PasswordReset($user));
|
||||||
|
}
|
||||||
|
}
|
||||||
42
app/Http/Controllers/Auth/VerificationController.php
Normal file
42
app/Http/Controllers/Auth/VerificationController.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use Illuminate\Foundation\Auth\VerifiesEmails;
|
||||||
|
|
||||||
|
class VerificationController extends Controller
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Email Verification Controller
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This controller is responsible for handling email verification for any
|
||||||
|
| user that recently registered with the application. Emails may also
|
||||||
|
| be re-sent if the user didn't receive the original email message.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use VerifiesEmails;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where to redirect users after verification.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $redirectTo = RouteServiceProvider::HOME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new controller instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('signed')->only('verify');
|
||||||
|
$this->middleware('throttle:6,1')->only('verify', 'resend');
|
||||||
|
}
|
||||||
|
}
|
||||||
43
app/Http/Controllers/Controller.php
Normal file
43
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||||
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||||
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||||
|
use Illuminate\Routing\Controller as BaseController;
|
||||||
|
use Prettus\Repository\Traits\Respondable;
|
||||||
|
use App\Events\ActionCalled;
|
||||||
|
|
||||||
|
class Controller extends BaseController
|
||||||
|
{
|
||||||
|
use AuthorizesRequests, DispatchesJobs, ValidatesRequests, Respondable;
|
||||||
|
|
||||||
|
public function gateAction($repository, $request, $id)
|
||||||
|
{
|
||||||
|
if(!$repository instanceof \Prettus\Repository\Contracts\RepositoryInterface){
|
||||||
|
throw new \Exception('The parameter $repository must be instance of Prettus\Repository\Contracts\RepositoryInterface', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$request->filled('action')){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request->validate([
|
||||||
|
'action' => 'string',
|
||||||
|
'params' => 'nullable|json',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = $repository->find($id);
|
||||||
|
|
||||||
|
if(!method_exists($data, 'callAction')){
|
||||||
|
throw new \Exception('The class ' . get_class($data) . ' must use App\Traits\ActionCallable trait', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data->callAction($request->action, $request->params);
|
||||||
|
|
||||||
|
event(new ActionCalled($data, $request->action, json_decode($request->params)));
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
app/Http/Controllers/HomeController.php
Normal file
28
app/Http/Controllers/HomeController.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class HomeController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a new controller instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware('auth');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the application dashboard.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\Support\Renderable
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return view('home');
|
||||||
|
}
|
||||||
|
}
|
||||||
69
app/Http/Kernel.php
Normal file
69
app/Http/Kernel.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||||
|
use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful;
|
||||||
|
|
||||||
|
class Kernel extends HttpKernel
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The application's global HTTP middleware stack.
|
||||||
|
*
|
||||||
|
* These middleware are run during every request to your application.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $middleware = [
|
||||||
|
\App\Http\Middleware\TrustProxies::class,
|
||||||
|
\Fruitcake\Cors\HandleCors::class,
|
||||||
|
\App\Http\Middleware\CheckForMaintenanceMode::class,
|
||||||
|
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||||
|
\App\Http\Middleware\TrimStrings::class,
|
||||||
|
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application's route middleware groups.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $middlewareGroups = [
|
||||||
|
'web' => [
|
||||||
|
\App\Http\Middleware\EncryptCookies::class,
|
||||||
|
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||||
|
\Illuminate\Session\Middleware\StartSession::class,
|
||||||
|
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||||
|
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||||
|
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||||
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
],
|
||||||
|
|
||||||
|
'api' => [
|
||||||
|
EnsureFrontendRequestsAreStateful::class,
|
||||||
|
'throttle:120,1',
|
||||||
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application's route middleware.
|
||||||
|
*
|
||||||
|
* These middleware may be assigned to groups or used individually.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $routeMiddleware = [
|
||||||
|
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||||
|
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||||
|
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||||
|
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||||
|
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||||
|
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||||
|
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||||
|
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||||
|
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||||
|
'auth.active' => \App\Http\Middleware\EnsureUserIsActive::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
21
app/Http/Middleware/Authenticate.php
Normal file
21
app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||||
|
|
||||||
|
class Authenticate extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the path the user should be redirected to when they are not authenticated.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
protected function redirectTo($request)
|
||||||
|
{
|
||||||
|
if (! $request->expectsJson()) {
|
||||||
|
return route('login');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
17
app/Http/Middleware/CheckForMaintenanceMode.php
Normal file
17
app/Http/Middleware/CheckForMaintenanceMode.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
|
||||||
|
|
||||||
|
class CheckForMaintenanceMode extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The URIs that should be reachable while maintenance mode is enabled.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $except = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
17
app/Http/Middleware/EncryptCookies.php
Normal file
17
app/Http/Middleware/EncryptCookies.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||||
|
|
||||||
|
class EncryptCookies extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The names of the cookies that should not be encrypted.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $except = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
23
app/Http/Middleware/EnsureUserIsActive.php
Normal file
23
app/Http/Middleware/EnsureUserIsActive.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
class EnsureUserIsActive
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
if(!$request->user()->active){
|
||||||
|
throw new \App\Exceptions\AccountNotActive;
|
||||||
|
}
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
27
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
27
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class RedirectIfAuthenticated
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @param string|null $guard
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next, $guard = null)
|
||||||
|
{
|
||||||
|
if (Auth::guard($guard)->check()) {
|
||||||
|
return redirect(RouteServiceProvider::HOME);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Http/Middleware/TrimStrings.php
Normal file
18
app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||||
|
|
||||||
|
class TrimStrings extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The names of the attributes that should not be trimmed.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $except = [
|
||||||
|
'password',
|
||||||
|
'password_confirmation',
|
||||||
|
];
|
||||||
|
}
|
||||||
23
app/Http/Middleware/TrustProxies.php
Normal file
23
app/Http/Middleware/TrustProxies.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Fideloper\Proxy\TrustProxies as Middleware;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class TrustProxies extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The trusted proxies for this application.
|
||||||
|
*
|
||||||
|
* @var array|string
|
||||||
|
*/
|
||||||
|
protected $proxies;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The headers that should be used to detect proxies.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $headers = Request::HEADER_X_FORWARDED_ALL;
|
||||||
|
}
|
||||||
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||||
|
|
||||||
|
class VerifyCsrfToken extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The URIs that should be excluded from CSRF verification.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $except = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
32
app/Http/Requests/Attachment/CreateRequest.php
Normal file
32
app/Http/Requests/Attachment/CreateRequest.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Attachment;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use App\Entities\Document;
|
||||||
|
|
||||||
|
class CreateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return Document::find($this->document_id)->creator_id == $this->user()->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'document_id' => 'required|exists:documents,id',
|
||||||
|
'attachments' => 'required|file',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/Http/Requests/Attachment/DestroyRequest.php
Normal file
31
app/Http/Requests/Attachment/DestroyRequest.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Attachment;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use App\Entities\Attachment;
|
||||||
|
|
||||||
|
class DestroyRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return Attachment::find($this->attachment)->document->creator_id == $this->user()->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/Attachment/IndexRequest.php
Normal file
30
app/Http/Requests/Attachment/IndexRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Attachment;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class IndexRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/Attachment/ShowRequest.php
Normal file
30
app/Http/Requests/Attachment/ShowRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Attachment;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ShowRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
35
app/Http/Requests/Attachment/UpdateRequest.php
Normal file
35
app/Http/Requests/Attachment/UpdateRequest.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Attachment;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use App\Entities\Document;
|
||||||
|
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return Document::find($this->document_id)->creator_id == $this->user()->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'document_id' => 'nullable|exists:documents,id',
|
||||||
|
'name' => 'nullable|string',
|
||||||
|
'extension' => 'nullable|string',
|
||||||
|
'size' => 'nullable|numeric',
|
||||||
|
'path' => 'nullable|string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/Http/Requests/Book/CreateRequest.php
Normal file
31
app/Http/Requests/Book/CreateRequest.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Book;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class CreateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->hasPermissionTo('Quản lý sổ văn bản');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => 'nullable|numeric|unique:books,id,'.$this->book,
|
||||||
|
'name' => 'required|string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/Book/DestroyRequest.php
Normal file
30
app/Http/Requests/Book/DestroyRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Book;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class DestroyRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->hasPermissionTo('Quản lý sổ văn bản');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/Book/IndexRequest.php
Normal file
30
app/Http/Requests/Book/IndexRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Book;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class IndexRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/Book/ShowRequest.php
Normal file
30
app/Http/Requests/Book/ShowRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Book;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ShowRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/Http/Requests/Book/UpdateRequest.php
Normal file
31
app/Http/Requests/Book/UpdateRequest.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Book;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->hasPermissionTo('Quản lý sổ văn bản');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => 'nullable|numeric|unique:books,id,'.$this->book,
|
||||||
|
'name' => 'nullable|string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
32
app/Http/Requests/Department/CreateRequest.php
Normal file
32
app/Http/Requests/Department/CreateRequest.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Department;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class CreateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->hasPermissionTo('Quản lý phòng ban');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => 'required|string|alpha_dash|max:7|unique:departments,id,'.$this->department,
|
||||||
|
'name' => 'required|string',
|
||||||
|
'tel' => 'nullable|alpha_num|max:15|unique:departments,tel,'.$this->tel,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/Department/DestroyRequest.php
Normal file
30
app/Http/Requests/Department/DestroyRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Department;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class DestroyRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->hasPermissionTo('Quản lý phòng ban');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/Department/IndexRequest.php
Normal file
30
app/Http/Requests/Department/IndexRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Department;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class IndexRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/Department/ShowRequest.php
Normal file
30
app/Http/Requests/Department/ShowRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Department;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ShowRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
32
app/Http/Requests/Department/UpdateRequest.php
Normal file
32
app/Http/Requests/Department/UpdateRequest.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Department;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->hasPermissionTo('Quản lý phòng ban');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => 'nullable|string|alpha_dash|max:7|unique:departments,id,'.$this->department,
|
||||||
|
'name' => 'nullable|string',
|
||||||
|
'tel' => 'nullable|alpha_num|max:15',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
58
app/Http/Requests/Document/CreateRequest.php
Normal file
58
app/Http/Requests/Document/CreateRequest.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Document;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use App\Entities\Book;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class CreateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
$typeName = Str::lower(Book::find($this->book_id)->name);
|
||||||
|
return $this->user()->hasPermissionTo('Quản lý '. $typeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => 'nullable|numeric|unique:documents,id',
|
||||||
|
'symbol' => 'nullable|string|max:30|unique:documents,symbol',
|
||||||
|
'abstract' => 'nullable|string',
|
||||||
|
'book_id' => 'required|exists:books,id',
|
||||||
|
'type_id' => 'required|exists:document_types,id',
|
||||||
|
'signer_id' => 'required|exists:signers,id',
|
||||||
|
'creator_id' => 'required|exists:users,id',
|
||||||
|
'writer_id' => 'nullable|exists:users,id',
|
||||||
|
'effective_at' => 'required|date',
|
||||||
|
'sign_at' => 'nullable|date',
|
||||||
|
'publisher_id' => 'required|exists:organizes,id',
|
||||||
|
'attachments.*' => 'nullable|file',
|
||||||
|
'link_id' => 'nullable|exists:documents,id',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all of the input and files for the request.
|
||||||
|
*
|
||||||
|
* @param array|mixed|null $keys
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function all($keys = null)
|
||||||
|
{
|
||||||
|
$data = parent::all($keys);
|
||||||
|
$data['creator_id'] = $this->user()->id;
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/Http/Requests/Document/DestroyRequest.php
Normal file
31
app/Http/Requests/Document/DestroyRequest.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Document;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use App\Entities\Document;
|
||||||
|
|
||||||
|
class DestroyRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return Document::find($this->document)->creator_id == $this->user()->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Http/Requests/Document/ExportRequest.php
Normal file
34
app/Http/Requests/Document/ExportRequest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Document;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ExportRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->hasPermissionTo('Báo cáo thống kê');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'book' => 'nullable|exists:books,id',
|
||||||
|
'type' => 'nullable|exists:document_types,id',
|
||||||
|
'from' => 'nullable|date',
|
||||||
|
'to' => 'nullable|date',
|
||||||
|
'export' => 'required|in:Xlsx,Csv,Xls,Html',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/Document/IndexRequest.php
Normal file
30
app/Http/Requests/Document/IndexRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Document;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class IndexRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/Document/ShowRequest.php
Normal file
30
app/Http/Requests/Document/ShowRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Document;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ShowRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
41
app/Http/Requests/Document/UpdateRequest.php
Normal file
41
app/Http/Requests/Document/UpdateRequest.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Document;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use App\Entities\Document;
|
||||||
|
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return Document::find($this->document)->creator_id == $this->user()->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => 'nullable|numeric|unique:documents,id,'.$this->document,
|
||||||
|
'symbol' => 'nullable|string|max:30',
|
||||||
|
'abstract' => 'nullable|string',
|
||||||
|
'book_id' => 'nullable|exists:books,id',
|
||||||
|
'type_id' => 'nullable|exists:document_types,id',
|
||||||
|
'signer_id' => 'nullable|exists:signers,id',
|
||||||
|
'writer_id' => 'nullable|exists:users,id',
|
||||||
|
'effective_at' => 'nullable|date',
|
||||||
|
'sign_at' => 'nullable|date',
|
||||||
|
'publisher_id' => 'nullable|exists:organizes,id',
|
||||||
|
'link_id' => 'nullable|exists:documents,id',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/Http/Requests/DocumentType/CreateRequest.php
Normal file
31
app/Http/Requests/DocumentType/CreateRequest.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\DocumentType;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class CreateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->hasPermissionTo('Quản lý loại văn bản');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => 'required|alpha_num|max:2|unique:document_types,id',
|
||||||
|
'name' => 'required|string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/DocumentType/DestroyRequest.php
Normal file
30
app/Http/Requests/DocumentType/DestroyRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\DocumentType;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class DestroyRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->hasPermissionTo('Quản lý loại văn bản');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/DocumentType/IndexRequest.php
Normal file
30
app/Http/Requests/DocumentType/IndexRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\DocumentType;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class IndexRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/DocumentType/ShowRequest.php
Normal file
30
app/Http/Requests/DocumentType/ShowRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\DocumentType;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ShowRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/Http/Requests/DocumentType/UpdateRequest.php
Normal file
31
app/Http/Requests/DocumentType/UpdateRequest.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\DocumentType;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->hasPermissionTo('Quản lý loại văn bản');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => 'nullable|alpha_num|max:2|unique:document_types,id,'.$this->document_type,
|
||||||
|
'name' => 'nullable|string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/Me/ShowRequest.php
Normal file
30
app/Http/Requests/Me/ShowRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Me;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ShowRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Http/Requests/Me/UpdateRequest.php
Normal file
34
app/Http/Requests/Me/UpdateRequest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Me;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'nullable|string',
|
||||||
|
'email' => 'nullable|email',
|
||||||
|
'password' => 'nullable|min:6|max:32|confirmed',
|
||||||
|
'tel' => 'nullable|string',
|
||||||
|
'birthday' => 'nullable|date',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Requests/Organize/CreateRequest.php
Normal file
30
app/Http/Requests/Organize/CreateRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Organize;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class CreateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->hasPermissionTo('Quản lý nơi ban hành');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user