Questions tagged [laravel-4]

Laravel 4.2 is the previous version of the open-source PHP web development MVC framework created by Taylor Otwell. Laravel helps you create applications using simple, expressive syntax.

Laravel 4.2 is the previous version of the open-source for web development created by Taylor Otwell. Laravel helps you create applications using simple, expressive syntax.

New Features Overview

  • All pieces have been decoupled into independent components, collectively called Illuminate
  • integration
  • Driver-based view system
  • Better integration with cloud storage
  • collections

Resources

See also the tag for general laravel based questions, from past versions.

Social Media

14441 questions
146
votes
8 answers

Dropping column with foreign key Laravel error: General error: 1025 Error on rename

I've created a table using migration like this: public function up() { Schema::create('despatch_discrepancies', function($table) { $table->increments('id')->unsigned(); $table->integer('pick_id')->unsigned(); …
Latheesan
  • 23,247
  • 32
  • 107
  • 201
146
votes
12 answers

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('abc AS a')->groupBy('col1')->toSql(); $num =…
quenty658
  • 1,587
  • 2
  • 10
  • 7
140
votes
9 answers

A JOIN With Additional Conditions Using Query Builder or Eloquent

I'm trying to add a condition using a JOIN query with Laravel Query Builder.
dede
  • 2,523
  • 2
  • 28
  • 32
139
votes
35 answers

Laravel blank white screen

My Laravel site was working before, I recently upgraded to Apache 2.4 and PHP 5.5.7. Now I'm getting a white blank screen when I go to laravel.mydomain.example, nothing in Apache error logs, routes and etc. should be fine as it worked…
Mico
  • 1,978
  • 2
  • 13
  • 17
136
votes
1 answer

Laravel. Use scope() in models with relation

I have two related models: Category and Post. The Post model has a published scope (method scopePublished()). When I try to get all categories with that scope: $categories = Category::with('posts')->published()->get(); I get an error: Call to…
Ilya Vo
  • 2,239
  • 3
  • 18
  • 31
136
votes
30 answers

Using Laravel Homestead: 'no input file specified'

I am new to using Laravel, and Homestead, and would appreciate any help or a point in the right direction. I have successfully been able to get to the "You have arrived" screen when I run "php artisan serve" but when I try to do the same thing via…
bryant
  • 2,041
  • 3
  • 18
  • 26
136
votes
24 answers

Laravel: Auth::user()->id trying to get a property of a non-object

I'm getting the following error "trying to get a property of a non-object" when I submit a form to add a user, the error is apparently on the first line: Auth::user()->id of the following: $id = Auth::user()->id; $currentuser =…
Josh
  • 5,999
  • 8
  • 30
  • 43
133
votes
4 answers

Managing relationships in Laravel, adhering to the repository pattern

While creating an app in Laravel 4 after reading T. Otwell's book on good design patterns in Laravel I found myself creating repositories for every table on the application. I ended up with the following table structure: Students: id, name Courses:…
ehp
  • 1,689
  • 3
  • 14
  • 20
127
votes
7 answers

How to get public directory?

I am a beginner here so pardon me for this question am using return File::put($path , $data); to create a file in public folder on Laravel. I used this piece of code from controller I need to know the value of $path how should it be.
Yasser Moussa
  • 2,209
  • 6
  • 26
  • 39
122
votes
34 answers

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. 'email' => 'unique:users,email_address,10' My validation rule is in the model so how do I pass the ID of the record to…
user742736
  • 2,629
  • 5
  • 30
  • 40
120
votes
7 answers

Preventing Laravel adding multiple records to a pivot table

I have a many to many relationship set up and working, to add an item to the cart I use: $cart->items()->attach($item); Which adds an item to the pivot table (as it should), but if the user clicks on the link again to add an item they have already…
Al_
  • 2,479
  • 7
  • 29
  • 43
119
votes
12 answers

Clone an Eloquent object including all relationships?

Is there any way to easily clone an Eloquent object, including all of its relationships? For example, if I had these tables: users ( id, name, email ) roles ( id, name ) user_roles ( user_id, role_id ) In addition to creating a new row in the users…
andrewtweber
  • 24,520
  • 22
  • 88
  • 110
119
votes
2 answers

How to get all rows (soft deleted too) from a table in Laravel?

To get all rows from a table, I have to use Model::all() but (from good reason) this doesn't gives me back the soft deleted rows. Is there a way I can accomplish this with Eloquent?
totymedli
  • 29,531
  • 22
  • 131
  • 165
119
votes
1 answer

Passing data to a closure in Laravel 4

I'm trying to use the Mail Class in Laravel 4, and I'm not able to pass variables to the $m object. the $team object contains data I grabbed from the DB with eloquent. Mail::send('emails.report', $data, function($m) { $m->to($team->senior->email,…
Benjamin Gonzalez
  • 1,343
  • 2
  • 9
  • 11
113
votes
6 answers

Laravel save / update many to many relationship

Can anyone help me on how to save many to many relationship? I have tasks, user can have many tasks and task can have many users (many to many), What I want to achieve is that in update form admin can assign multiple users to specific task. This is…
SuperManSL
  • 1,306
  • 2
  • 12
  • 17