{"id":1618,"date":"2022-08-30T15:18:02","date_gmt":"2022-08-30T15:18:02","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/problem-about-eloquent-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:18:02","modified_gmt":"2022-08-30T15:18:02","slug":"problem-about-eloquent-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-eloquent-collection-of-common-programming-errors\/","title":{"rendered":"problem about eloquent-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c1201849caa3693e9b41824351c9dc3d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRubens Mariuzzo<br \/>\nlaravel eloquent laravel-3<br \/>\nWhen I am creating a snippet model I want to directly add a relational record to the intermediate table but I get this error:Unhandled ExceptionMessage: Method [save] is not defined on the Query class.When I execute this code:$new_snippet = new Snippet(array(&#8216;snippet&#8217; =&gt; Input::get(&#8216;snippet&#8217;), &#8216;title&#8217; =&gt; Input::get(&#8216;title&#8217;)) );foreach (Input::get(&#8216;categorie_ids&#8217;) as $categorie_id) {$categorie = Categorie::find($categorie_id)-&gt;snippet()-&gt;save($new_snippet); }I&#8217;m relatively new to wor<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/016cdb9ef71ae41514284cf8bbe12576?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nVictor Bjelkholm<br \/>\nphp relationship laravel eloquent laravel-3<br \/>\nI&#8217;m trying to show a snippet of code and in the same time display comments that you can make to the snippets (I call the snippets code). But I&#8217;m having troubles to view the username of the user who made each and every comment. I expect to have each user when I&#8217;m calling with(array(&#8216;user&#8217;, &#8216;comments&#8217;, &#8216;comments.user&#8217;)) but I just get an unhandled exception.\/\/Models class Code extends Eloquent {public function user() {return $this-&gt;belongs_to(&#8216;User&#8217;);}public function comments() {return $this-&amp;<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0501842f3538f820b769d345236d35c0?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\njgalak<br \/>\nphp laravel-4 eloquent<br \/>\nI am trying to create an application in PHP\/Laravel 4, and having a problem. I have a situation where I need to track multiple names for a given person, one of which is primary. I have the tables defined as follows:Schema::create(&#8216;names&#8217;, function($table) {$table-&gt;increments(&#8216;id&#8217;);$table-&gt;string(&#8216;name&#8217;);$table-&gt;integer(&#8216;person&#8217;);$table-&gt;timestamps();$table-&gt;softDeletes(); });Schema::create(&#8216;people&#8217;, function($table) {$table-&gt;increments(&#8216;id&#8217;);$table-&gt;integer(&#8216;primary_name&#8217;)<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fd3e5171cbc1f277daacacef4967bceb?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPhill Sparks<br \/>\nmany-to-many laravel pivot-table laravel-4 eloquent<br \/>\nI&#8217;m working with the following models: Game, User and Player where Player extends User. In this case Game and Player have a relationship of N:N and User extends Confide. So code stands like:app\/models\/Game.php&lt;?phpclass Game extends Eloquent {protected $guarded = array();protected $table = &#8216;users&#8217;;public $timestamps = false;public function players(){return $this-&gt;belongsToMany(&#8216;Player&#8217;);} }app\/models\/User.php&lt;?phpuse Zizaco\\Confide\\ConfideUser;class User extends ConfideUser {protected $<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9b221b61a151461bc2ad706a68d248d7?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDanaia<br \/>\nlaravel laravel-4 eloquent<br \/>\nI have 2 tables: &#8216;users&#8217; and &#8216;nests&#8217; and 1 pivot table: &#8216;nest_user&#8217;. In my pivot table I have email addresses I want to filter against so I can grab all the nests which have the associated email addreses. Here is my scehma:public function up() {Schema::create(&#8216;users&#8217;, function(Blueprint $table){$table-&gt;increments(&#8216;id&#8217;);$table-&gt;string(&#8216;username&#8217;);$table-&gt;text(&#8216;bio&#8217;);$table-&gt;string(&#8216;picture&#8217;);$table-&gt;string(&#8217;email&#8217;);$table-&gt;string(&#8216;password&#8217;);$table-&gt;integer(&#8216;visits&#8217;);$table-&amp;<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/dae8c00cd0b4e0c6ea1fa796a918362c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nStewi<br \/>\nphp laravel laravel-4 eloquent<br \/>\nI have a function that sends out group emails but I need to access the list of contacts from a particular group. I have tried EagerLoading and chaining but can&#8217;t seem to get it working. So in the sendCommunications() function, this line is causing me issues:$contacts = $message-&gt;group-&gt;contact()-&gt;select(array(&#8217;email_address&#8217;));The error message I receive from the command line is:Call to undefined method Illuminate\\\\Database\\\\Eloquent\\\\Collection::contact()And this is what I have so far:<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9a7101fe3ba50e621e91ee1edf9d27bb?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNyxynyx<br \/>\nphp laravel laravel-4 eloquent<br \/>\nThere are 2 models Product and Variant where a Product hasMany Variant and a Variant belongsTo Product. Both models also contain many other relationships.Question: How can you use Eloquent to select all Variants -&gt;where(&#8216;color&#8217;,&#8217;red&#8217;) and also its related Product must satisfy -&gt;where(&#8216;price&#8217;, &#8216;&gt;&#8217; &#8217;50&#8217;)? All the relationships of Variant in the returned resultset must be retained.When a join is used on the Eloquent model, all relationships are lost except for the products which was joined<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/bc3b740851837ebf3d833f0113279d00?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRGweb<br \/>\nphp laravel relationship laravel-4 eloquent<br \/>\nI&#8217;ve been trying to get the hang of Laravel. I&#8217;m using Laravel 4. Right now I have two tables, a &#8216;Products&#8217; table and a &#8216;Images&#8217; table. A product can have many images and an image belongs to a product.So I have two models:class Product extends Eloquent {public function images(){return $this-&gt;hasMany(&#8216;Image&#8217;);}}class Image extends Eloquent {protected $table = &#8216;product_images&#8217;;public function product(){return $this-&gt;belongsTo(&#8216;Product&#8217;);}}Now I&#8217;m building the &#8216;index&#8217; page of a resource, so I<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/hhv4h.jpg?s=32&amp;g=1\" \/><br \/>\nMelvin<br \/>\ndatabase transactions laravel eloquent<br \/>\nFrom the laravel documentation: Database Transaction. It says that:DB::transaction(function() {DB::table(&#8216;users&#8217;)-&gt;update(array(&#8216;votes&#8217; =&gt; 1));DB::table(&#8216;posts&#8217;)-&gt;delete(); });Here, 1 is explicitly entered to update the users&#8230; I tried this using a variable,$id = 3; DB::transaction(function() {DB::table(&#8216;users&#8217;)-&gt;where(&#8216;id&#8217;,&#8217;=&#8217;,$id)-&gt;get(); });It throws an error:Undefined variable: idI also tried to place to $id as a parameter like this:$id = 3; DB::transaction(function() {DB::t<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/cf8d4ef9561383b953a468d603547361?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nGuns<br \/>\nphp mysql laravel laravel-4 eloquent<br \/>\nI am a newbie to Laravel. Please excuse me if this question sounds kiddish.I have a modelclass Config extends Eloquent {public static $table = &#8216;configs&#8217;;}and the controller goes asclass UserController extends BaseController {Public function getIndex (){$config_items = Config::all ();var_dump ( $config_items );return View::make ( &#8216;user.userindex&#8217; )-&gt; with ( &#8216;title&#8217;, &#8216;User Page&#8217; );}}But when i try to access the Config model, i am getting the error:Symfony \\ Component \\ Debug \\ Exception \\ Fatal<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fcfe027198e89be013ec38a53b99d57b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRaoul Van den Berge<br \/>\nphp laravel laravel-4 eloquent<br \/>\nIt seems like Laravel 4 cannot get an relation when I use the ::where() syntax. So this is what I have:&lt;?php\/\/ works fine$questions = Auth::user()-&gt;questions;\/\/ error$questions = User::where(&#8216;profilename&#8217;, &#8216;=&#8217;, $username)-&gt;questions;\/\/ error$questions = User::where(&#8216;profilename&#8217;, &#8216;=&#8217;, $username)-&gt;get()-&gt;questions; ?&gt;The first method just works fine, but the second an third not.These give the following error: &#8220;Undefined property: Illuminate\\Database\\Eloquent\\Builder::$questions<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/420ccaa000a5e86e492034f9770594a4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ncoryj<br \/>\nphp laravel eloquent<br \/>\nI have an availability calendar that I&#8217;m trying to POST to my database using Laravel. When i dump out my POST I get this..string(1440) &#8220;s:1430:&#8221;2012-11-06;;1;;888,2012-11-07;;1;;888,2012-11-08;; 1;;888,2012-11-09;;1;;888,2012-11-10;;1;;888,2012-11-11;;1;;888,2012-11-12;; 1;;888,2012-11 13;;1;;888,2012-11-14;;1;;888,2012-11-15;;1;;888,2012-11-16;;1;; 888,2012-11-17;;1;;888,2012-11-18;;1;;888,2012-11-19;;1;;888,2012-11-20;;1;;888, 2012-11-21;;1;;888,2012-11-22;;1;;888,2012-11-23;;1;;888,2012-11-24<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/255caf19fa33d65f187589e6c1ccaf97?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\npeaks<br \/>\nphp mysql laravel eloquent laravel-3<br \/>\nI&#8217;ve got 4 tables:My relationships should work like this:Items can only have one size, color and category.This should be working but it&#8217;s really not. The query generated returns wrong results.Here are my model files:&lt;?phpclass Shop_Item extends Eloquent {public static $table = &#8216;items&#8217;;public static $timestamps = false;public function scategory() {return $this-&gt;has_one(&#8216;Shop_Category&#8217;,&#8217;id&#8217;);}public function ssize() {return $this-&gt;has_one(&#8216;Shop_Size&#8217;,&#8217;id&#8217;);}public function scolor() {retur<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0dfc777363112efc81cb0d40b88813e3?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMere Development<br \/>\nlaravel eloquent laravel-3<br \/>\nI&#8217;m struggling with a One to Many relationship and Eloquent. I have Events (As in show events), and I have Locations. Each Event is tied to one location, but each Location might be used to host many Events. (One)Location-to-(Many)Events.Here are my models:class Iaevent extends Eloquent {public static $timestamps = true;public function locations() {return $this-&gt;has_one(&#8216;Location&#8217;);} }class Location extends Eloquent {public static $timestamps = true;public function iaevents() {return $this-&gt;<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-11-27 12:05:19. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Rubens Mariuzzo laravel eloquent laravel-3 When I am creating a snippet model I want to directly add a relational record to the intermediate table but I get this error:Unhandled ExceptionMessage: Method [save] is not defined on the Query class.When I execute this code:$new_snippet = new Snippet(array(&#8216;snippet&#8217; =&gt; Input::get(&#8216;snippet&#8217;), &#8216;title&#8217; =&gt; Input::get(&#8216;title&#8217;)) );foreach (Input::get(&#8216;categorie_ids&#8217;) as $categorie_id) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,1],"tags":[],"class_list":["post-1618","post","type-post","status-publish","format-standard","hentry","category-laravel","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1618","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1618"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1618\/revisions"}],"predecessor-version":[{"id":8874,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1618\/revisions\/8874"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}