use DB::transaction
This commit is contained in:
@@ -6,12 +6,12 @@ use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use Spatie\Permission\Traits\HasPermissions;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use App\Models\UserActivityLog;
|
||||
use App\Models\LogList;
|
||||
use DB;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
@@ -60,95 +60,101 @@ class User extends Authenticatable
|
||||
|
||||
public function addActivityComplete($log_unique_code, $model = null)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
// DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$temp = new UserActivityLog();
|
||||
$temp->user_id = $this->id;
|
||||
$temp->username = $this->username;
|
||||
$temp->user_name = $this->name;
|
||||
$temp->user_first_name = $this->first_name;
|
||||
$temp->user_last_name = $this->last_name;
|
||||
$temp->position = $this->position;
|
||||
$temp->mobile = $this->mobile;
|
||||
$temp->province_id = $this->province_id;
|
||||
$temp->province_fa = $this->province_fa;
|
||||
$temp->city_id = $this->city_id;
|
||||
$temp->city_fa = $this->city_fa;
|
||||
DB::transaction(function () use ($log_unique_code, $model) {
|
||||
$temp = new UserActivityLog();
|
||||
$temp->user_id = $this->id;
|
||||
$temp->username = $this->username;
|
||||
$temp->user_name = $this->name;
|
||||
$temp->user_first_name = $this->first_name;
|
||||
$temp->user_last_name = $this->last_name;
|
||||
$temp->position = $this->position;
|
||||
$temp->mobile = $this->mobile;
|
||||
$temp->province_id = $this->province_id;
|
||||
$temp->province_fa = $this->province_fa;
|
||||
$temp->city_id = $this->city_id;
|
||||
$temp->city_fa = $this->city_fa;
|
||||
|
||||
$log = LogList::where('log_unique_code', $log_unique_code)->first();
|
||||
$temp->log_unique_code = $log_unique_code;
|
||||
$temp->description = $log->description;
|
||||
$temp->action_type = $log->action_type;
|
||||
|
||||
$temp->agent = request()->header('user-agent') ?? null;
|
||||
$temp->method = request()->method() ?? null;
|
||||
$temp->ip = request()->ip() ?? null;
|
||||
$temp->url = request()->Url() ?? null;
|
||||
$temp->query_parameter = serialize(request()->all());
|
||||
|
||||
$temp->model = serialize($model) ?? null;
|
||||
$temp->save();
|
||||
DB::commit();
|
||||
$log = LogList::where('log_unique_code', $log_unique_code)->first();
|
||||
$temp->log_unique_code = $log_unique_code;
|
||||
$temp->description = $log->description;
|
||||
$temp->action_type = $log->action_type;
|
||||
|
||||
$temp->agent = request()->header('user-agent') ?? null;
|
||||
$temp->method = request()->method() ?? null;
|
||||
$temp->ip = request()->ip() ?? null;
|
||||
$temp->url = request()->Url() ?? null;
|
||||
$temp->query_parameter = serialize(request()->all());
|
||||
|
||||
$temp->model = serialize($model) ?? null;
|
||||
$temp->save();
|
||||
});
|
||||
// DB::commit();
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
// DB::rollBack();
|
||||
try {
|
||||
$temp = new UserActivityLog();
|
||||
$temp->user_id = $this->id;
|
||||
$temp->username = $this->username;
|
||||
$temp->user_name = $this->name;
|
||||
$temp->user_first_name = $this->first_name;
|
||||
$temp->user_last_name = $this->last_name;
|
||||
$temp->position = $this->position;
|
||||
$temp->mobile = $this->mobile;
|
||||
$temp->province_id = $this->province_id;
|
||||
$temp->province_fa = $this->province_fa;
|
||||
$temp->city_id = $this->city_id;
|
||||
$temp->city_fa = $this->city_fa;
|
||||
DB::transaction(function () use ($log_unique_code, $model) {
|
||||
$temp = new UserActivityLog();
|
||||
$temp->user_id = $this->id;
|
||||
$temp->username = $this->username;
|
||||
$temp->user_name = $this->name;
|
||||
$temp->user_first_name = $this->first_name;
|
||||
$temp->user_last_name = $this->last_name;
|
||||
$temp->position = $this->position;
|
||||
$temp->mobile = $this->mobile;
|
||||
$temp->province_id = $this->province_id;
|
||||
$temp->province_fa = $this->province_fa;
|
||||
$temp->city_id = $this->city_id;
|
||||
$temp->city_fa = $this->city_fa;
|
||||
|
||||
$log = LogList::where('log_unique_code', $log_unique_code)->first();
|
||||
$temp->log_unique_code = $log_unique_code;
|
||||
$temp->description = $log->description;
|
||||
$temp->action_type = $log->action_type;
|
||||
|
||||
$temp->agent = request()->header('user-agent') ?? null;
|
||||
$temp->method = request()->method() ?? null;
|
||||
$temp->ip = request()->ip() ?? null;
|
||||
$temp->url = request()->Url() ?? null;
|
||||
$temp->query_parameter = serialize(request()->input());
|
||||
|
||||
$temp->model = serialize($model) ?? null;
|
||||
$temp->save();
|
||||
DB::commit();
|
||||
$log = LogList::where('log_unique_code', $log_unique_code)->first();
|
||||
$temp->log_unique_code = $log_unique_code;
|
||||
$temp->description = $log->description;
|
||||
$temp->action_type = $log->action_type;
|
||||
|
||||
$temp->agent = request()->header('user-agent') ?? null;
|
||||
$temp->method = request()->method() ?? null;
|
||||
$temp->ip = request()->ip() ?? null;
|
||||
$temp->url = request()->Url() ?? null;
|
||||
$temp->query_parameter = serialize(request()->input());
|
||||
|
||||
$temp->model = serialize($model) ?? null;
|
||||
$temp->save();
|
||||
});
|
||||
// DB::commit();
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
$temp = new UserActivityLog();
|
||||
$temp->user_id = $this->id;
|
||||
$temp->username = $this->username;
|
||||
$temp->user_name = $this->name;
|
||||
$temp->user_first_name = $this->first_name;
|
||||
$temp->user_last_name = $this->last_name;
|
||||
$temp->position = $this->position;
|
||||
$temp->mobile = $this->mobile;
|
||||
$temp->province_id = $this->province_id;
|
||||
$temp->province_fa = $this->province_fa;
|
||||
$temp->city_id = $this->city_id;
|
||||
$temp->city_fa = $this->city_fa;
|
||||
// DB::rollBack();
|
||||
DB::transaction(function () use ($log_unique_code, $model) {
|
||||
$temp = new UserActivityLog();
|
||||
$temp->user_id = $this->id;
|
||||
$temp->username = $this->username;
|
||||
$temp->user_name = $this->name;
|
||||
$temp->user_first_name = $this->first_name;
|
||||
$temp->user_last_name = $this->last_name;
|
||||
$temp->position = $this->position;
|
||||
$temp->mobile = $this->mobile;
|
||||
$temp->province_id = $this->province_id;
|
||||
$temp->province_fa = $this->province_fa;
|
||||
$temp->city_id = $this->city_id;
|
||||
$temp->city_fa = $this->city_fa;
|
||||
|
||||
$log = LogList::where('log_unique_code', $log_unique_code)->first();
|
||||
$temp->log_unique_code = $log_unique_code;
|
||||
$temp->description = $log->description;
|
||||
$temp->action_type = $log->action_type;
|
||||
|
||||
$temp->agent = request()->header('user-agent') ?? null;
|
||||
$temp->method = request()->method() ?? null;
|
||||
$temp->ip = request()->ip() ?? null;
|
||||
$temp->url = request()->Url() ?? null;
|
||||
$temp->query_parameter = "Request is to big !!!!!";
|
||||
|
||||
$temp->model = serialize($model) ?? null;
|
||||
$temp->save();
|
||||
DB::commit();
|
||||
$log = LogList::where('log_unique_code', $log_unique_code)->first();
|
||||
$temp->log_unique_code = $log_unique_code;
|
||||
$temp->description = $log->description;
|
||||
$temp->action_type = $log->action_type;
|
||||
|
||||
$temp->agent = request()->header('user-agent') ?? null;
|
||||
$temp->method = request()->method() ?? null;
|
||||
$temp->ip = request()->ip() ?? null;
|
||||
$temp->url = request()->Url() ?? null;
|
||||
$temp->query_parameter = "Request is to big !!!!!";
|
||||
|
||||
$temp->model = serialize($model) ?? null;
|
||||
$temp->save();
|
||||
});
|
||||
// DB::commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user