lundi 4 juillet 2016

Setting properties in laravel model

I have the the following Post model.

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $fillable = [
        'app_id',
        'title',
        'content'
  ];

    private $app_id;

    public function __construct()
    {
        $this->app_id = 43;
    }

}

I am trying to save a new post with the following code:

  $post = new Post();
  $post->title="Test title";
  $post->content="Test content";
  $post->save();

This gets saved, however the app_id isn't getting saved. Any ideas why it doesn't simply get set when I new up the object?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire