selam arkadaslar.gecmis bayramınız kutlu olsun.
eloquent model de firstOrCreate kullanıyorum..bunu niye kullanıyorum cunku model event calıstırmak istedigimde sadece bununla calıstırabildim..
sorunum soyle..
app/models/admin
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Admin extends Model
{
protected $guarded = array('id');
protected $hidden=array("password");
protected $table="prosystem_administrator";
//protected $dates = ['deleted_at'];
public static function boot()
{
parent::boot();
static::created(function()
{
app()->make("Base")->getService("stats")->field("general_counts")->obj("admin")->set();
app()->make("Base")->getService("stats")->field("post_process")->obj("insert")->set();
});
static::deleted(function()
{
//
});
}
}
model dosyam bu..şimdi rest api üzerinden cliente insert işlemi yaptırdıgımda..şu kodu calıstırıyorum..
return \App\Models\Admin::firstOrCreate($this->config->postdata($data));
postdata json soyle olsun..client bana soyle gonderiyor
{"username":"blabla","email":"foo@gmail.com"}
basit haliyle bu..tabloda username ve email alanı unique zaten istesede duplicate yapamıyor..
buraya kadar herşey normal amma velakin
query bana her türlü true donuyor..
yani adam duplicate yaptıgında bile true gonderiyom
{
success : true
..
..
}
boyle gonderiyorum...buda sacma oluyor..işlem false ama ben adama success true gonderiyom..
....insert();
kullandıgımda false gonderiyorum ama..bu seferde model eventi yakalayamıyorum..sacma bir dongunun icindeyim acıkcası