laravel updateOrCreate() with dynamic table -


i'm working project tables created time depending on user adding new properties, model have below

    class hotel extends model {     public function __construct($hotel)     {         $this->table = $hotel;     }      protected $fillable = ['date', 'sold', 'sold_diff', 'rev', 'rev_diff', 'row', 'date_col', 'sold_col', 'rev_col'];  } 

and can use table in controller doing

$hotel_table = new hotel($table); 

but use model::updateorcreate() when i'm adding or updating rows in table, , i'm not sure how that.

this signature updateorcreate function "static model updateorcreate( array $attributes, array $values = array())"

for update or create, can pass condition must met update table first argument , values updated second.

for example.

  $primarykey = isset($request->input('id')) ? $request->input('id') : null;    $mymodel = model::updateorcreate(['id' => $primarykey], $request->all()); 

so if id in request object table updated if not new record created.


Comments

Popular posts from this blog

shader - OpenGL Shadow Map -

stringtemplate - StringTemplate4 if conditional with length -