Complete BLoC with Clean Architecture (group chat) Discount !! E-commerce App With Backend Source Code Video and Voice Chatting App Firebase Chatting App Source Code Complete Gym App BLoC State Management Source Code Complete Study App Buy Ticket Booking App Source Code Buy Travel App With Backend Source Code Complete Chat App Udemy Course Special Offer Discount !! Online Learning Course App (BLoC) Online Learning Course App (Riverpod) Online Learning Course App (Getx) Discount !! Shopping App (Provider) Cool Flutter Game Flutter Nodejs Chat App Flutter Nodejs Api And Firebase Chat App Riverpod Task Management App
Here's E-commerce app order model. The app is buit using Flutter and Laravel api with Laravel backend. This order model could be used for the api and front end could be Flutter or React Native.
To be able to work with this, make sure you have Order table in the database. If some of the methods are not used in the app tutorial you can remove them.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
use Encore\Admin\Traits\DefaultDatetimeFormat;
class Order extends Model
{
use DefaultDatetimeFormat;
protected $casts = [
'order_amount' => 'float',
'total_tax_amount' => 'float',
'delivery_address_id' => 'integer',
'delivery_charge' => 'float',
'user_id' => 'integer',
'scheduled' => 'integer',
'details_count' => 'integer',
'created_at' => 'datetime',
'updated_at' => 'datetime'
];
public function setDeliveryChargeAttribute($value)
{
$this->attributes['delivery_charge'] = round($value, 3);
}
public function details()
{
return $this->hasMany(OrderDetail::class);
}
public function scopeNotpos($query)
{
return $query->where('order_type', '<>' , 'pos');
}
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
public function delivery_man()
{
return $this->belongsTo(DeliveryMan::class, 'delivery_man_id');
}
public function scopeOrderScheduledIn($query, $interval)
{
return $query->where(function($query)use($interval){
$query->whereRaw('created_at <> scheduled_at')->where(function($q) use ($interval) {
$q->whereBetween('scheduled_at', [Carbon::now()->toDateTimeString(),Carbon::now()->addMinutes($interval)->toDateTimeString()]);
})->orWhere('scheduled_at','<',Carbon::now()->toDateTimeString());
})->orWhereRaw('created_at = scheduled_at');
}
public function Type(){
return $this->hasOne(Type::class, 'type_id', 'type_id');
}
}