problem about eloquent-Collection of common programming errors


  • 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(‘snippet’ => Input::get(‘snippet’), ‘title’ => Input::get(‘title’)) );foreach (Input::get(‘categorie_ids’) as $categorie_id) {$categorie = Categorie::find($categorie_id)->snippet()->save($new_snippet); }I’m relatively new to wor

  • Victor Bjelkholm
    php relationship laravel eloquent laravel-3
    I’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’m having troubles to view the username of the user who made each and every comment. I expect to have each user when I’m calling with(array(‘user’, ‘comments’, ‘comments.user’)) but I just get an unhandled exception.//Models class Code extends Eloquent {public function user() {return $this->belongs_to(‘User’);}public function comments() {return $this-&

  • jgalak
    php laravel-4 eloquent
    I 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(‘names’, function($table) {$table->increments(‘id’);$table->string(‘name’);$table->integer(‘person’);$table->timestamps();$table->softDeletes(); });Schema::create(‘people’, function($table) {$table->increments(‘id’);$table->integer(‘primary_name’)

  • Phill Sparks
    many-to-many laravel pivot-table laravel-4 eloquent
    I’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<?phpclass Game extends Eloquent {protected $guarded = array();protected $table = ‘users’;public $timestamps = false;public function players(){return $this->belongsToMany(‘Player’);} }app/models/User.php<?phpuse Zizaco\Confide\ConfideUser;class User extends ConfideUser {protected $

  • Danaia
    laravel laravel-4 eloquent
    I have 2 tables: ‘users’ and ‘nests’ and 1 pivot table: ‘nest_user’. 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(‘users’, function(Blueprint $table){$table->increments(‘id’);$table->string(‘username’);$table->text(‘bio’);$table->string(‘picture’);$table->string(’email’);$table->string(‘password’);$table->integer(‘visits’);$table-&

  • Stewi
    php laravel laravel-4 eloquent
    I 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’t seem to get it working. So in the sendCommunications() function, this line is causing me issues:$contacts = $message->group->contact()->select(array(’email_address’));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:

  • Nyxynyx
    php laravel laravel-4 eloquent
    There 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 ->where(‘color’,’red’) and also its related Product must satisfy ->where(‘price’, ‘>’ ’50’)? 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

  • RGweb
    php laravel relationship laravel-4 eloquent
    I’ve been trying to get the hang of Laravel. I’m using Laravel 4. Right now I have two tables, a ‘Products’ table and a ‘Images’ 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->hasMany(‘Image’);}}class Image extends Eloquent {protected $table = ‘product_images’;public function product(){return $this->belongsTo(‘Product’);}}Now I’m building the ‘index’ page of a resource, so I

  • Melvin
    database transactions laravel eloquent
    From the laravel documentation: Database Transaction. It says that:DB::transaction(function() {DB::table(‘users’)->update(array(‘votes’ => 1));DB::table(‘posts’)->delete(); });Here, 1 is explicitly entered to update the users… I tried this using a variable,$id = 3; DB::transaction(function() {DB::table(‘users’)->where(‘id’,’=’,$id)->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

  • Guns
    php mysql laravel laravel-4 eloquent
    I am a newbie to Laravel. Please excuse me if this question sounds kiddish.I have a modelclass Config extends Eloquent {public static $table = ‘configs’;}and the controller goes asclass UserController extends BaseController {Public function getIndex (){$config_items = Config::all ();var_dump ( $config_items );return View::make ( ‘user.userindex’ )-> with ( ‘title’, ‘User Page’ );}}But when i try to access the Config model, i am getting the error:Symfony \ Component \ Debug \ Exception \ Fatal

  • Raoul Van den Berge
    php laravel laravel-4 eloquent
    It seems like Laravel 4 cannot get an relation when I use the ::where() syntax. So this is what I have:<?php// works fine$questions = Auth::user()->questions;// error$questions = User::where(‘profilename’, ‘=’, $username)->questions;// error$questions = User::where(‘profilename’, ‘=’, $username)->get()->questions; ?>The first method just works fine, but the second an third not.These give the following error: “Undefined property: Illuminate\Database\Eloquent\Builder::$questions

  • coryj
    php laravel eloquent
    I have an availability calendar that I’m trying to POST to my database using Laravel. When i dump out my POST I get this..string(1440) “s:1430:”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

  • peaks
    php mysql laravel eloquent laravel-3
    I’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’s really not. The query generated returns wrong results.Here are my model files:<?phpclass Shop_Item extends Eloquent {public static $table = ‘items’;public static $timestamps = false;public function scategory() {return $this->has_one(‘Shop_Category’,’id’);}public function ssize() {return $this->has_one(‘Shop_Size’,’id’);}public function scolor() {retur

  • Mere Development
    laravel eloquent laravel-3
    I’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->has_one(‘Location’);} }class Location extends Eloquent {public static $timestamps = true;public function iaevents() {return $this->