Create routes and views for customers and their addresses.
This commit is contained in:
@@ -8,4 +8,20 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
class Address extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'is_address',
|
||||
'is_delivery',
|
||||
'name',
|
||||
'email',
|
||||
'phone',
|
||||
'address',
|
||||
'city',
|
||||
'state',
|
||||
'country',
|
||||
'zip',
|
||||
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,77 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class Customer extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are appended with attribute getters.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $appends = [
|
||||
'created',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the created_at attribute in local time format.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCreatedAttribute(): string
|
||||
{
|
||||
return $this->created_at->format('d.m.Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the invoice address.
|
||||
*
|
||||
* @return HasOne
|
||||
*/
|
||||
public function address(): HasOne
|
||||
{
|
||||
return $this->hasOne(Address::class)->ofMany([],
|
||||
function (Builder $query) {
|
||||
$query->where('is_address', '=', true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the delivery address.
|
||||
*
|
||||
* @return HasOne
|
||||
*/
|
||||
public function delivery(): HasOne
|
||||
{
|
||||
return $this->hasOne(Address::class)->ofMany([],
|
||||
function (Builder $query) {
|
||||
$query->where('is_delivery', '=', true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all customer's addresses.
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function addresses(): HasMany
|
||||
{
|
||||
return $this->hasMany(Address::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user