I was searching a solution like that, great idea !
@bernardonigbinde
6 ай бұрын
If you don’t want to have to call these all over your code, it’s probably powerful to use this in model events - maybe with Observers.
@emekatimothyiloba699
6 ай бұрын
Thank you for sharing
@iCodeArtisan
6 ай бұрын
Good implementation
@amitsolanki9363
5 ай бұрын
In incrementMetric() why used increment() method? I think this is also work same if directly pass wnd parameter $value inside firstOrCreate() instead of attaching increment ()
@shubhamsahuSD
6 ай бұрын
Awesome
@LlegoManuel
6 ай бұрын
Upsert does not seem to work with mysql without an unique key. Not sure if it's a bug, but I'd like to hear if anyone else had this problem
@TapanSharma.
6 ай бұрын
yeah, its an issue related to the database
@LaravelDaily
6 ай бұрын
It's how MySQL works, unrelated to Laravel upsert. Unfortunately not much we can do here.
@uaer309
6 ай бұрын
Didn't work for me with PgSQL too. Ended up altering the schema a bit with `$table->unique(['name', 'month', 'year', 'model_id', 'model_type'], 'metrics_unique_constraint');`. Also `upsert` didn't automatically add the model properties to the table so I had to change the upsert as well: $this->metrics()->upsert([ 'name' => $name, 'month' => $month ?? now()->month, 'year' => $year ?? now()->year, 'value' => $value, 'model_id' => $this->id, 'model_type' => get_class($this), ], ['name', 'month', 'year', 'model_id', 'model_type'], update: ['value' => DB::raw("metrics.value + $value")]);
@alisalmabadi
6 ай бұрын
Although the codes are too clear but please share them as a gist😢 thanks
Пікірлер: 14