update code
This commit is contained in:
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',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user