<?php

namespace Orchestra\Model;

use Closure;
use Orchestra\Support\Fluent;
use Illuminate\Database\Eloquent\Model;
use Orchestra\Contracts\Support\Transformable;

abstract class Eloquent extends Model implements Transformable
{
    use Traits\Faker;

    /**
     * Determine if the model instance uses soft deletes.
     *
     * @return bool
     */
    public function isSoftDeleting(): bool
    {
        return property_exists($this, 'forceDeleting') && $this->forceDeleting === false;
    }

    /**
     * Execute a Closure within a transaction.
     *
     * @param  \Closure  $callback
     *
     * @throws \Throwable
     *
     * @return mixed
     */
    public function transaction(Closure $callback)
    {
        return $this->getConnection()->transaction($callback);
    }

    /**
     * Transform each attribute in the model using a callback.
     *
     * @param  callable  $callback
     *
     * @return \Illuminate\Support\Fluent
     */
    public function transform(callable $callback)
    {
        return new Fluent($callback($this));
    }
}

<?php

namespace Orchestra\Model;

use Closure;
use Orchestra\Support\Fluent;
use Illuminate\Database\Eloquent\Model;
use Orchestra\Contracts\Support\Transformable;

abstract class Eloquent extends Model implements Transformable
{
    use Traits\Faker;

    /**
     * Determine if the model instance uses soft deletes.
     *
     * @return bool
     */
    public function isSoftDeleting(): bool
    {
        return property_exists($this, 'forceDeleting') && $this->forceDeleting === false;
    }

    /**
     * Save the model to the database if exists.
     *
     * @param  array  $options
     *
     * @return bool
     */
    public function saveIfExists(array $options = []): bool
    {
        if ($this->exists === false) {
            return false;
        }

        return $this->save($options);
    }

    /**
     * Save the model to the database using transaction if exists.
     *
     * @param  array  $options
     *
     * @return bool
     */
    public function saveIfExistsOrFail(array $options = []): bool
    {
        if ($this->exists === false) {
            return false;
        }

        return $this->saveOrFail($options);
    }

    /**
     * Execute a Closure within a transaction.
     *
     * @param  \Closure  $callback
     *
     * @throws \Throwable
     *
     * @return mixed
     */
    public function transaction(Closure $callback)
    {
        return $this->getConnection()->transaction($callback);
    }

    /**
     * Transform each attribute in the model using a callback.
     *
     * @param  callable  $callback
     *
     * @return \Orchestra\Support\Fluent
     */
    public function transform(callable $callback)
    {
        return new Fluent($callback($this));
    }
}

Add save only if exists.
Add save only if exists.

Signed-off-by: Mior Muhammad Zaki <e1a543840a942eb68427510a8a483282a7bfeddf@gmail.com>
