restore composer.json, add mysqli extension
This commit is contained in:
104
app/Http/Requests/Dashboard/Category/Request.php
Executable file
104
app/Http/Requests/Dashboard/Category/Request.php
Executable file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Dashboard\Category;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Request extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if ($this->isMethod('get')) {
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
'name' => 'required|array',
|
||||
'name.*' => 'required|string',
|
||||
'image' => 'nullable|mimes:jpg,jpeg,png',
|
||||
'parent_id' => 'nullable',
|
||||
'brands' => 'nullable|array',
|
||||
'position' => 'nullable|numeric'
|
||||
];
|
||||
}
|
||||
|
||||
public function getName(): array
|
||||
{
|
||||
return $this->get('name');
|
||||
}
|
||||
|
||||
public function getSlug(): string
|
||||
{
|
||||
return Str::slug($this->get('name')['uz']);
|
||||
}
|
||||
|
||||
public function getImage(): string
|
||||
{
|
||||
if ($this->hasFile('image')) {
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
$folder = "uploads/categories";
|
||||
|
||||
return (string) $this->file('image')->store($folder);
|
||||
} else {
|
||||
return $this->file('image')->store('uploads/categories', 'local');
|
||||
}
|
||||
} else {
|
||||
return 'null';
|
||||
}
|
||||
}
|
||||
|
||||
public function getPublished()
|
||||
{
|
||||
if ($this->get('published') == 'true') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFilterPower()
|
||||
{
|
||||
if ($this->get('is_filter_power') == 'true') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getCredit()
|
||||
{
|
||||
if ($this->get('credit') == 'true') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getParentId()
|
||||
{
|
||||
if ($this->get('parent_id') > 0)
|
||||
return $this->get('parent_id');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getPosition(): int
|
||||
{
|
||||
return $this->get('position');
|
||||
}
|
||||
|
||||
public function getPopular(): bool
|
||||
{
|
||||
if ($this->get('popular') == 'false') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
113
app/Http/Requests/Dashboard/Category/Update.php
Executable file
113
app/Http/Requests/Dashboard/Category/Update.php
Executable file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Dashboard\Category;
|
||||
|
||||
use App\Models\Category;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Update extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if ($this->isMethod('get')) {
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
'name' => 'required|array',
|
||||
'name.*' => 'required|string',
|
||||
'image' => 'nullable',
|
||||
'parent_id' => 'nullable',
|
||||
'popular' => 'nullable',
|
||||
'brands' => 'nullable|array',
|
||||
'position' => 'nullable|numeric'
|
||||
];
|
||||
}
|
||||
|
||||
public function getName(): array
|
||||
{
|
||||
return $this->get('name');
|
||||
}
|
||||
|
||||
public function getSlug(): string
|
||||
{
|
||||
return Str::slug($this->get('name')['uz']);
|
||||
}
|
||||
|
||||
public function getImage(Category $category): string
|
||||
{
|
||||
if ($this->hasFile('image')) {
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
// delete old image from s3
|
||||
Storage::disk('s3')->delete($category->image);
|
||||
|
||||
$folder = "uploads/categories";
|
||||
|
||||
return (string) $this->file('image')->store($folder);
|
||||
} else {
|
||||
// detele old image
|
||||
if (is_file($category->image)) {
|
||||
unlink($category->image);
|
||||
}
|
||||
return $this->file('image')->store('uploads/categories', 'local');
|
||||
}
|
||||
} else {
|
||||
return 'null';
|
||||
}
|
||||
}
|
||||
|
||||
public function getFilterPower()
|
||||
{
|
||||
if ($this->get('is_filter_power') == 'true') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getPublished()
|
||||
{
|
||||
if ($this->get('published') == 'true') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getCredit()
|
||||
{
|
||||
if ($this->get('credit') == 'true') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getParentId()
|
||||
{
|
||||
if ($this->get('parent_id') > 0)
|
||||
return $this->get('parent_id');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getPosition(): int
|
||||
{
|
||||
return $this->get('position');
|
||||
}
|
||||
|
||||
public function getPopular(): bool
|
||||
{
|
||||
if ($this->get('popular') == 'false') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user