laravel-4

Laravel 4 - Inserting multiple records when using the hasMany relationship

别等时光非礼了梦想. 提交于 2019-12-09 12:55:44
问题 Still finding my feet with Laravel 4 and I'm a little unsure as to why this isn't working. In L3 I was able to insert multiple records to a table like so... $comments = array( array('message' => 'A new comment.'), array('message' => 'A second comment.'), ); $post = Post::find(1); $post->comments()->save($comments); However when I try to do similar now either the records are inserted without the foreign key, like so... $comments = array( array('message' => 'A new comment.'), array('message' =>

How to extend laravel 4 core?

早过忘川 提交于 2019-12-09 11:20:26
问题 I am a newb learning laravel 4. I want to override specific helper functions. Or add new functions to Url, Str etc. How to do this? 回答1: Depending on what part of Laravel you want to extend or replace, there are different approaches. Macros Adding functions to Str is really easy, because of "macros": Here's a short example for adding function: Str::macro('test', function($str) { return 'Testing: ' . $str . '!'; }); You can then call this function as expected: echo Str::test('text'); //

Laravel: rendering partial views with AJAX requests

我是研究僧i 提交于 2019-12-09 10:51:20
问题 I am trying to make a single page CRUD application and I am using AJAX with jQuery. In this case, I submit the form and store a new country in my database asynchronously and then render a partial view with the new data. This is my script and the method that retrieves the countries from the database and returns the partial view. $('#create-country-form').submit(function(event) { $.post('/country/store', $('#create-country-form').serialize(), function() { $.get('/country/all', function(data) {

Link with icon in Laravel 4

橙三吉。 提交于 2019-12-09 10:27:17
问题 Can someone help to rewrite this, from HTML to Laravel4? <a href="index.php" ><span><i class="icon-home"></i></span> Home </a> The route name for that page is just '/'. I know how to write simple link in Laravel: {{ HTML::link('/','Home) }} But how can I add the span class with the font-awesome icon? 回答1: I'd just put the link in the href. <a href="{{ url('/') }}"><span><i class="icon-home"></i></span> Home</a> No need to generate all the rest through Laravel. 回答2: What @Dries suggests is

How to: mass assign an update in Laravel 4?

做~自己de王妃 提交于 2019-12-09 07:35:47
问题 This is an for internal app, mass assignment security is not an issue in this case. I'm dealing with very large (numerous) form fields, so mass assigning the user edits would be great. Mass assignment seems to work fine with 'create()' but not with doing a find & save. This is what I have: $post_data = Input::all(); $formobj = HugeForm::find($id); $formobj->save($post_data); How do I go about it? I'd rather not specify many dozens of form inputs. 回答1: You should be able to use fill(array

Migrations fail when SQLite database file does not exist?

不羁岁月 提交于 2019-12-09 07:33:24
问题 It seems that migrations (sort of) fail silently when the database file does not exist. The migration executes but no db file is created and I can run the migration again. (It never says "nothing to migrate") If I create a blank file then it works. This is odd because I thought SQLite always created the db file if it was not found so I'm not sure if this is a bug or something I've done wrong. Maybe it's a permissions problem? But everything else is working so I don't know. I'm using Windows 7

laravel services.json not created

主宰稳场 提交于 2019-12-09 06:45:56
问题 Sometimes my services.json is missing after running composer update or php artisan clear-compiled . I checked the permissions and even changed it to 777 on the storage folder but it does not help. How can I debug whats wrong? There are no entries in my laravel log and nothing in my apache log. I'm using "laravel/framework": "4.1.*" 回答1: Just run a php artisan serve and stop, this will create the services.json file. 回答2: Ensure your web server has access to the files/folders specifically app

Vagrant - Homestead Setup Multiple sites

自古美人都是妖i 提交于 2019-12-09 06:17:35
问题 I have mapped the folders etc using the homestead.yaml; ip: "192.168.10.10" ... folders: - map: /Users/User/Desktop/folder/Homestead/First to: /home/vagrant/First - map: /Users/User/Desktop/folder/Homestead/Second to: /home/vagrant/Second sites: - map: first.dev to: /home/vagrant/First/public - map: second.dev to: /home/vagrant/Second/public But when i set up the hosts file, etc/hosts with my second.dev to 192.168.10.10 i find that the mapping goes to first.dev, not the mapping that i have

Laravel - Artisan not working

若如初见. 提交于 2019-12-09 05:08:56
问题 I'm aware of the other questions out there, but they are different to my situation. I installed a fresh copy of my own laravel, and I tried running php artisan list , which works. Now, I have a colleague who has installed a copy of laravel himself, and he pushes his entire directory onto a git repository. I pulled the entire branch off the repository, and tried running php artisan list , but nothing happens this time. I mean, literally, nothing happens. Any ideas as to why this is happening?

How to update a collection using Eloquent Laravel

你离开我真会死。 提交于 2019-12-09 04:40:34
问题 I have a one to many relationship between Device and Command models (each Device has many commands ). Now I want to update a collection of commands using save() method. So, I used the following code: $device = Device::find(1); $commands = $device->commands()->whereStatus("pending")->get(); $commands->status = "sent"; $commands->save(); But I got a FatalErrorException exception with an error message of Call to undefined method Illuminate\Database\Eloquent\Collection::save() . In other words, I