All Questions

185
votes
13answers
221502 views

How to create multiple where clause query using Laravel Eloquent?

I'm using the Laravel Eloquent query builder and I have query where I want a WHERE clause on multiple things. It works, but it is not elegant. Example: $results = User:: where('this', '=', 1...
139
votes
19answers
216691 views

Laravel, get last insert id using Eloquent

I'm currently using this code to insert data in a table: public function saveDetailsCompany() { $post = Input::All(); $data = new Company; $data->nombre = $post['name']; $data-&g...
70
votes
7answers
99320 views

Get specific columns using "with()" function in Laravel Eloquent

I have two tables User and Post One User have many posts and one post belongs to only one user. In my User Model I have hasMany relation like public function post(){ return $this->hasman...
41
votes
5answers
55197 views

How to select from subquery using Laravel Query Builder?

I'd like to get value by the following SQL using Eloquent ORM. - SQL SELECT COUNT(*) FROM (SELECT * FROM abc GROUP BY col1) AS a; Then I considered the following. - Code $sql = Abc::from('ab...
68
votes
7answers
86542 views

Bulk Insertion in Laravel using eloquent ORM

How can we perform bulk database insertions in Laravel using Eloquent ORM? I want to accomplish this in Laravel: https://stackoverflow.com/a/10615821/600516 but I am getting the following error. ...
162
votes
7answers
173790 views

Laravel 4 eloquent WHERE with OR AND OR?

How do I say WHERE (a=1 OR b=1) AND (c=1 OR d=1) For more complicated queries am I supposed to use raw SQL?
73
votes
5answers
54337 views

Laravel check if related model exists

I have an Eloquent model which has a related model: public function option() { return $this->hasOne('RepairOption', 'repair_item_id'); } public function setOptionArrayAttribute($values) { ...
157
votes
20answers
167559 views

Get the query executed in Laravel 3/4

How can I get the executed query in Laravel 3/4, using Fluent Query Builder or Eloquent ORM. For example: DB::table('users')->where_status(1)->get(); Or (posts (id, user_id, ...)) User::fin...
124
votes
7answers
113304 views

Add a custom attribute to a Laravel / Eloquent model on load?

I'd like to be able to add a custom attribute/property to an Laravel/Eloquent model when it is loaded, similar to how that might be achieved with RedBean's $model->open() method. For instance, at ...
12
votes
2answers
7095 views

Friendship system with Laravel : Many to Many relationship

I'm trying to create a Friendship system with Laravel (I'm starting with it) but I'm blocked with relationships. Here's the thing : there is one table Users and one table Friends which contains the fo...

Previous Next