reupload
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\GlobalOrder\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ecommerce\Product\Order\Status\OrderStatus;
|
||||
use App\Modules\GlobalOrder\Controllers\Requests\GlobalOrderStoreRequest;
|
||||
use App\Modules\GlobalOrder\Models\GlobalOrder;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class GlobalOrderController extends Controller
|
||||
{
|
||||
/**
|
||||
* Store resource
|
||||
*/
|
||||
public function store(GlobalOrderStoreRequest $request): JsonResponse
|
||||
{
|
||||
$globalOrder = GlobalOrder::create([
|
||||
'customer_name' => $request->customer_name,
|
||||
'customer_phone' => $request->customer_phone,
|
||||
'customer_address' => $request->customer_address,
|
||||
'payment_type' => $request->payment_type,
|
||||
'notes' => $request->notes,
|
||||
'order_website' => $request->order_website,
|
||||
'status' => OrderStatus::default(),
|
||||
'user_id' => auth()->id(),
|
||||
]);
|
||||
|
||||
if ($request->hasFile('images')) {
|
||||
$globalOrder->addMultipleMediaFromRequest(['images'])
|
||||
->each(function ($fileAdder) {
|
||||
$fileAdder->toMediaCollection('uploads');
|
||||
});
|
||||
}
|
||||
|
||||
return response()->rest([], 201, 'Created successfully');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\GlobalOrder\Controllers\Requests;
|
||||
|
||||
use App\Models\Ecommerce\Product\Order\Payment\OrderPayment;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\File as FileRule;
|
||||
|
||||
class GlobalOrderStoreRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'customer_name' => ['required', 'string', 'max:255'],
|
||||
'customer_phone' => ['required', 'integer', 'between:61000000,71999999'],
|
||||
'customer_address' => ['nullable', 'string', 'max:255'],
|
||||
'payment_type' => ['required', 'string', Rule::in(array_keys(OrderPayment::oldButGoodTypes()))],
|
||||
'notes' => ['nullable', 'string', 'max:255'],
|
||||
'order_website' => ['nullable', 'string', 'max:255'],
|
||||
'images.*' => ['nullable', FileRule::image()->min('1kb')->max('10mb')],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the error messages for the defined validation rules.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'payment_type.in' => sprintf('Valid sources: %s', implode(', ', array_keys(
|
||||
OrderPayment::oldButGoodTypes()
|
||||
))),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('global_orders', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->string('customer_name')->nullable();
|
||||
$table->string('customer_address')->nullable();
|
||||
$table->string('customer_phone')->nullable();
|
||||
$table->string('order_website')->nullable();
|
||||
$table->text('images')->nullable();
|
||||
$table->string('payment_type')->nullable();
|
||||
|
||||
$table->string('status');
|
||||
$table->string('notes')->nullable();
|
||||
|
||||
$table->foreignId('user_id')->nullable()->constrained()->cascadeOnDelete();
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('global_orders');
|
||||
}
|
||||
};
|
||||
63
app/Modules/GlobalOrder/Models/GlobalOrder.php
Normal file
63
app/Modules/GlobalOrder/Models/GlobalOrder.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\GlobalOrder\Models;
|
||||
|
||||
use App\Models\Ecommerce\Product\Order\Concerns\HasStatus;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Spatie\Image\Manipulations;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
|
||||
class GlobalOrder extends Model implements HasMedia
|
||||
{
|
||||
use HasFactory;
|
||||
use HasStatus;
|
||||
use InteractsWithMedia;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'customer_name',
|
||||
'customer_address',
|
||||
'customer_phone',
|
||||
'order_website',
|
||||
'images',
|
||||
'payment_type',
|
||||
'status',
|
||||
'notes',
|
||||
'user_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* Media collections
|
||||
*/
|
||||
public function registerMediaCollections(): void
|
||||
{
|
||||
$this->addMediaCollection('uploads')
|
||||
->useFallbackUrl(url('/assets/web/images/05.jpg'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Media Conversions
|
||||
*/
|
||||
public function registerMediaConversions(?Media $media = null): void
|
||||
{
|
||||
$this->addMediaConversion('thumb200x200')
|
||||
->fit(Manipulations::FIT_CONTAIN, 200, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* User
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
211
app/Modules/GlobalOrder/Nova/Resources/GlobalOrderResource.php
Normal file
211
app/Modules/GlobalOrder/Nova/Resources/GlobalOrderResource.php
Normal file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\GlobalOrder\Nova\Resources;
|
||||
|
||||
use App\Models\Ecommerce\Product\Order\Payment\OrderPayment;
|
||||
use App\Models\Ecommerce\Product\Order\Status\OrderStatus;
|
||||
use App\Modules\GlobalOrder\Models\GlobalOrder;
|
||||
use App\Nova\Resource;
|
||||
use App\Nova\Resources\User\UserSearchResource;
|
||||
use Ebess\AdvancedNovaMediaLibrary\Fields\Images;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Nova\Fields\Badge;
|
||||
use Laravel\Nova\Fields\BelongsTo;
|
||||
use Laravel\Nova\Fields\DateTime;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Select;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||
use Nurmuhammet\NovaInputmask\NovaInputmask;
|
||||
|
||||
class GlobalOrderResource extends Resource
|
||||
{
|
||||
/**
|
||||
* The model the resource corresponds to.
|
||||
*
|
||||
* @var class-string<\App\Modules\GlobalOrder\Models\GlobalOrder>
|
||||
*/
|
||||
public static $model = GlobalOrder::class;
|
||||
|
||||
/**
|
||||
* The relationships that should be eager loaded on index queries.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public static $with = ['user'];
|
||||
|
||||
/**
|
||||
* The single value that should be used to represent the resource when being displayed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $title = 'customer_name';
|
||||
|
||||
/**
|
||||
* The columns that should be searched.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public static $search = [
|
||||
'customer_name', 'customer_phone',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the displayable label of the resource.
|
||||
*/
|
||||
public static function label(): string
|
||||
{
|
||||
return __('Global orders');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the displayable singular label of the resource.
|
||||
*/
|
||||
public static function singularLabel(): string
|
||||
{
|
||||
return __('Global order');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fields displayed by the resource.
|
||||
*/
|
||||
public function fields(NovaRequest $request): array
|
||||
{
|
||||
return [
|
||||
ID::make()->sortable(),
|
||||
|
||||
Images::make(__('Image'), 'uploads')
|
||||
->conversionOnIndexView('thumb200x200'),
|
||||
|
||||
Text::make(__('Name'), 'customer_name')
|
||||
->rules(['required', 'string', 'max:255']),
|
||||
|
||||
Text::make(__('Address'), 'customer_address')
|
||||
->rules(['required', 'string', 'max:255']),
|
||||
|
||||
NovaInputmask::make(__('Customer phone'), 'customer_phone')
|
||||
->mask(phoneMaskFormat())
|
||||
->storeRawValue()
|
||||
->sortable(),
|
||||
|
||||
Text::make(__('Order website'), 'order_website')
|
||||
->rules(['required', 'string', 'max:255']),
|
||||
|
||||
Text::make(__('Notes'), 'notes')
|
||||
->rules(['required', 'string', 'max:255']),
|
||||
|
||||
Select::make(__('App'), 'payment_type')
|
||||
->displayUsingLabels()
|
||||
->options(OrderPayment::oldButGoodTypes())
|
||||
->sortable(),
|
||||
|
||||
Badge::make('Status')
|
||||
->map(OrderStatus::classes())
|
||||
->labels(OrderStatus::values())
|
||||
->addTypes([
|
||||
'primary' => 'dark:bg-gray-900 bg-gray-600 text-white',
|
||||
])
|
||||
->sortable(),
|
||||
|
||||
DateTime::make(__('Created at'), 'created_at')
|
||||
->displayUsing(fn ($value) => $value->format('H:i, d.m.Y'))
|
||||
->exceptOnForms()
|
||||
->sortable(),
|
||||
|
||||
BelongsTo::make(__('User'), 'user', UserSearchResource::class)
|
||||
->searchable()
|
||||
->withSubtitles(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cards available for the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function cards(NovaRequest $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filters available for the resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filters(NovaRequest $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lenses available for the resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function lenses(NovaRequest $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actions available for the resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function actions(NovaRequest $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the resource should be available for the given request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function authorizedToViewAny(Request $request)
|
||||
{
|
||||
return auth()->user() && auth()->user()->isAdmin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the current user can view the given resource.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorizedToView(Request $request)
|
||||
{
|
||||
|
||||
return auth()->user() && auth()->user()->isAdmin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the current user can create new resources.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function authorizedToCreate(Request $request)
|
||||
{
|
||||
return auth()->user() && auth()->user()->isAdmin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the current user can update the given resource.
|
||||
*/
|
||||
public function authorizedToUpdate(Request $request): bool
|
||||
{
|
||||
return auth()->user() && auth()->user()->isAdmin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the current user can delete the given resource.
|
||||
*/
|
||||
public function authorizedToDelete(Request $request): bool
|
||||
{
|
||||
if (auth()->user()->isMe()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user