Is there a way to merge 2 relationships in laravel? this is the way it’s setup now, but Is there a way I could return both merged? public function CompetitionsHome() { return $this->HasMany(…
Tag: laravel-4
Laravel Eloquent – Attach vs Sync
What is the difference between attach() and sync() in Laravel 4’s Eloquent ORM? I’ve tried to look around but couldn’t find anything! Answer attach(): Insert related models when working with many-to-many relations No array parameter is expected Example: sync(): Similar to the attach() method…
How to specify Books and Authors relationship in Eloquent insertion?
I was figuring out how to insert a hasMany entry using Laravel 4 Author.php module Book.php Module My controller I’m getting one null record on authors table which pointed to the book and other 3 record that I inserted here without any pointing to the book. Answer First off I believe this is wrong schem…
Laravel Check If Related Model Exists
I have an Eloquent model which has a related model: When I create the model, it does not necessarily have a related model. When I update it, I might add an option, or not. So I need to check if the related model exists, to either update it, or create it, respectively: Where <related_model_exists> is the…
How to reload/refresh model from database in Laravel?
In some of my tests, I have a user model I have created and I run some methods that need to save certain attributes. In rails, I would typically call something like user.reload which would repopulate the attributes from the database. Is there a way in laravel to do that? I read through the api and couldn̵…
Laravel: Validation unique on update
I know this question has been asked many times before but no one explains how to get the id when you’re validating in the model. My validation rule is in the model so how do I pass the ID of the record to the validation rule. Here is my models/User models/BaseModel Answer One simple solution. In your Mo…
Laravel blade – Add a class if a condition is met
This is simple but I can’t seem to be able to do it with blade and I usually go back to php for this but, since I can’t declare a new php variable with blade (without printing it, that is) how should …
Laravel change input value
In laravel, we can get the input value via Input::get(‘inputname’). I try to change the value by doing this Input::get(‘inputname’) = “new value”;. But then, I get the error message saying Can’t use function return value in write context. Is it possible for us change …
laravel class not found (works on localhost but not on DO server)
This is a repeat question – eg: Laravel 4 migrations – class not found However, I’ve tried every solution (from every forum I could find) and cannot figure this out. Scenario I created a Laravel 4 project on my local machine – added some classes, controllers, views, etc – the pro…
laravel compact() and ->with()
I have a piece of code and I’m trying to find out why one variation works and the other doesn’t. return View::make(‘gameworlds.mygame’, compact(‘fixtures’), compact(‘teams’))->with(‘selections’, $…