dimanche 13 octobre 2019

How to insert data directly inside model Laravel?

There is model:

namespace App;

use Illuminate\Database\Eloquent\Model;

class Command extends Model
{  
   public function send($userId, $id) {}
}

I want to insert data in send method directly in model, how to do that?

I have tried:

 public function send($userId, $id) {
    $this->insert(["id" => $id, "userid" => $userId]);
 }

I can use DB object in send() like:

DB::table('users')->insert(
    ["id" => $id, "userid" => $userId]
);


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2OFugBj
via IFTTT

Aucun commentaire:

Enregistrer un commentaire