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
210
votes
14 answers

How to delete all the rows in a table using Eloquent?

My guess was to use the following syntax: MyModel::all()->delete(); But that did not work. I'm sure it's super simple, but I've searched for documentation on the subject and can't find it!
Pete
  • 7,289
  • 10
  • 39
  • 63
202
votes
2 answers

What are the Differences Between "php artisan dump-autoload" and "composer dump-autoload"?

I am pretty new to Laravel 4 and Composer. While I do Laravel 4 tutorials, I couldn't understand the difference between those two commands; php artisan dump-autoload and composer dump-autoload What's the difference between them?
Naing Lin Aung
  • 3,373
  • 4
  • 31
  • 48
200
votes
10 answers

How to alias a table in Laravel Eloquent queries (or using Query Builder)?

Lets say we are using Laravel's query builder: $users = DB::table('really_long_table_name') ->select('really_long_table_name.id') ->get(); I'm looking for an equivalent to this SQL: really_long_table_name AS short_name This…
prograhammer
  • 20,132
  • 13
  • 91
  • 118
198
votes
11 answers

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) { $this->option->update($values); } When I create the…
Tom Macdonald
  • 6,433
  • 7
  • 39
  • 59
194
votes
28 answers

PHP Composer update "cannot allocate memory" error (using Laravel 4)

I just can't solve this one. I'm on Linode 1G RAM basic plan. Trying to install a package via Composer and it's not letting me. My memory limit is set to "-1" on PHP.ini Is there anything else I can do to get this installed? Loading composer…
ericbae
  • 9,604
  • 25
  • 75
  • 108
186
votes
33 answers

file_put_contents(meta/services.json): failed to open stream: Permission denied

I am new to Laravel. I was trying to open http://localhost/test/public/ and I got Error in exception handler. I googled around and changed the permission of storage directory using chmod -R 777 app/storage but to no avail. I changed debug=>true…
vishnub1626
  • 2,063
  • 2
  • 14
  • 14
185
votes
20 answers

Composer killed while updating

I got a problem, I tried to install a new package to my Laravel 4 project. But when I run php composer.phar update I get this: Loading composer repositories with package information Updating dependencies (including require-dev) Killed I have looked…
cherrycoding
  • 1,855
  • 2
  • 14
  • 19
183
votes
18 answers

Laravel Eloquent groupBy() AND also return count of each group

I have a table that contains, amongst other columns, a column of browser versions. And I simply want to know from the record-set, how many of each type of browser there are. So, I need to end up with something like this: Total Records: 10; Internet…
kJamesy
  • 5,973
  • 5
  • 20
  • 22
175
votes
4 answers

Laravel - Route::resource vs Route::controller

I read the docs on the Laravel website, Stack Overflow, and Google but still don't understand the difference between Route::resource and Route::controller. One of the answers said Route::resource was for crud. However, with Route::controller we can…
Sonique
  • 6,670
  • 6
  • 41
  • 60
173
votes
4 answers

MVC (Laravel) where to add logic

Let's say whenever I do a CRUD operation or modify a relationship in a specific way I also want to do something else. E.g., whenever someone publishes a post I also want to save something to a table for analytics. Maybe not the best example but in…
Sabrina Leggett
  • 9,079
  • 7
  • 47
  • 50
158
votes
14 answers

Laravel Pagination links not including other GET parameters

I am using Eloquent together with Laravel 4's Pagination class. Problem: When there are some GET parameters in the URL, eg: http://site.example/users?gender=female&body=hot, the pagination links produced only contain the page parameter and nothing…
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
157
votes
17 answers

How can I resolve "Your requirements could not be resolved to an installable set of packages" error?

When I run composer update I receive some wired output. Here is my composer.json look like. { "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", …
code-8
  • 54,650
  • 106
  • 352
  • 604
157
votes
19 answers

In Laravel, the best way to pass different types of flash messages in the session

I'm making my first app in Laravel and am trying to get my head around the session flash messages. As far as I'm aware in my controller action I can set a flash message either by going Redirect::to('users/login')->with('message', 'Thanks for…
harryg
  • 23,311
  • 45
  • 125
  • 198
156
votes
18 answers

Laravel daily log created with wrong permissions

I have a script that I run using php artisan (with root user), and sometimes it causes the daily log file to be created before the apache www-data user does - which means that when a real user uses my web application, I get the folder permission…
NiRR
  • 4,782
  • 5
  • 32
  • 60
154
votes
4 answers

Best Practices for Laravel 4 Helpers and Basic Functions?

I'm trying to understand the best place to put a global function in Laravel 4. For example, date formatting. I don't think making a facade is worth it as facades are too modular. I've read articles about creating a library folder and storing classes…
Jason Spick
  • 6,028
  • 13
  • 40
  • 59