Note that there are some explanatory texts on larger screens.

plurals
  1. POLaravel Saving A Model And Relationships
    text
    copied!<p>I have the following Model:</p> <pre><code>class Movie extends Eloquent { protected $primaryKey = "movie_id"; public function detail() { return $this-&gt;hasOne('Detail'); } public function firstpage() { return $this-&gt;hasOne('Firstpage'); } public function country() { return $this-&gt;belongsToMany('Countries','movies_countries','movie_id','country_id'); } public function year() { return $this-&gt;hasOne('Years'); } public function media() { return $this-&gt;hasMany('Media'); } } </code></pre> <p>This is the Model of interest:</p> <pre><code>class Years extends Eloquent { protected $table = 'movies_years'; protected $primaryKey = "relation_id"; public function movie() { return $this-&gt;belongsTo('Movie'); } </code></pre> <p>The DBTable for years has a field "movie_year" and "movie_id"</p> <p>So, I have following problem, or understanding issue:</p> <p>I'm trying to update the Model Years with new Data, but can't seem the get it done. I tried the following:</p> <pre><code>$movies = Movie::find($tmp['movie_id']); $movies-&gt;title = $tmp['title']; $movies-&gt;title_product = $tmp['title_product']; $movies-&gt;title_orginal = $tmp['title_original']; $movies-&gt;year = array('movie_year' =&gt; $tmp['movieyears']); $movies-&gt;push(); </code></pre> <p>The eye is on the $movies->year row, everything else works fine.</p> <p>I also tried something stupid like:</p> <pre><code>$movies-&gt;year() = array('movie_year' =&gt; $tmp['movieyears']); </code></pre> <p>I don't know how to update the Years Model, which has a relation with the Movie Model.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload