laravel-4

Update multiple rows of database in Laravel

瘦欲@ 提交于 2019-12-07 02:17:07
问题 I want a code for update multiple rows of database, somthing like this: UPDATE values SET data='{"options":["male","female"],"default":"male"}' where project_id=1 and id=1; UPDATE values SET data='{"options":["male","female"],"default":"male"}' where project_id=1 and id=2; UPDATE values SET data='{"options":["male","female"],"default":"male"}' where project_id=1 and id=3; After some hours i could get result with something like this in laravel framework: $values = Value::where('project_id',

Laravel 4, Composer and hybridauth - How to load additional providers

六眼飞鱼酱① 提交于 2019-12-07 01:23:05
问题 I'm using Laravel 4 and have loaded hybridauth via composer and got it working just fine with Facebook and Twitter. Now i'm trying to get it working with Steam, which is listed as an additional provider, however I keep getting the following error: require_once(vendor/hybridauth/hybridauth/hybridauth/Hybrid/Providers/Steam.php) [function.require-once]: failed to open stream: No such file or directory Clearly it's looking in the wrong place, the actual class resides in this location: vendor

Laravel != operator in where not working

馋奶兔 提交于 2019-12-07 01:15:27
问题 This query is returning null when an object is expected. $vow = DB::table('media_featured')->where('is_video_of_the_week', 1)-> where('video_of_week_expired', '!=', 1)->first(); CREATE TABLE `media_featured` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `media_id` int(10) unsigned DEFAULT NULL, `is_video_of_the_week` tinyint(1) DEFAULT NULL, `is_featured` tinyint(1) DEFAULT NULL, `video_of_week_expired` tinyint(1) DEFAULT NULL, `featured_expired` tinyint(1) DEFAULT NULL, `created_at`

How to get a Builder object from rows related to pivot - Laravel

为君一笑 提交于 2019-12-07 00:26:29
I'm trying to get all the "books" that one user have: but I can't do it how I need. I use the following code: /*Gets all books from the user whose id is 1*/ $books= User::find(1)->books(); That return to me an Collection object; but I need a Builder object, as I get when I use the "select" method. /* This code return me a "Builder" object */ Books::select(array('id', 'name', 'type')); I need the Builder instead of Collection because I using Bllim/Datatables on my project and this package just accept a Builder object... If I send it a Collection its throw me the next error (500 - Internal

How to use str_replace in laravel

牧云@^-^@ 提交于 2019-12-06 22:55:41
问题 how to use php function str_replace in laravel framework. My array key names on table columns name so keys have '_' like first_name, last_name etc. i want to remove these '_' in blade file. my requirement is string replace in .blade.php file. i am trying this php code but it's useless. <th>{{str_replace('_', ' ', $str)}}</th> thanks 回答1: You can use php code in .blade.php file try like this <th> <?=str_replace('_', ' ', $str)?> </th> 回答2: Which version of Laravel did you use? For laravel 5.x,

302 redirect after CORS preflight

匆匆过客 提交于 2019-12-06 21:28:35
问题 I'm running into a problem with a 302 redirect after my CORS preflight has successfully returned a 200 status. I'm currently building an app using Laravel 4.1 and Angular 1.2 as well as my own OAUTH2 server. The error that Chrome/FF/Safari are sending back to me is: XMLHttpRequest cannot load http://localhost.api/api/v1/tracks?$filter=id%20eq%20guid%27d7de10ba-e353-455b-a3cb-ced9b4965141%27& . The request was redirected to ' http://localhost.api/session/invalid ', which is disallowed for

Laravel 4 - Sending the input back on a failed submission

强颜欢笑 提交于 2019-12-06 20:23:25
I have this form @extends('index') @section('main') <h1>Create a new poll</h1> {{ Form::model(new Poll, ['route' => 'polls.store', 'class' => 'create-poll']) }} <div class="gray-box"> {{ Form::label("topic", "Write your poll question") }} {{ Form::text('topic', '', ['placeholder' => 'Example: What is the best number?', 'id' => 'topic']) }} </div> <div class="gray-box"> {{ Form::label(null, "Write the possible answers") }} {{ Form::text('option[]', null, ['class' => 'option', 'placeholder' => 'Test option']) }} <input type="button" class="more-options" value="Add another option"> {{-- This will

Cannot send session cookie - headers already sent PHPUnit / Laravel

◇◆丶佛笑我妖孽 提交于 2019-12-06 19:43:51
问题 I have this strange problem when i call the parent::setUp() on my TestCase class for unit test a class when i run phpunit it throw me this error: 1) MatchRequestRepositoryTest::test_find_requests_by_match_id ErrorException: session_start(): Cannot send session cookie - headers already sent by (output started at /var/www/project.dev/vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:459) What can be the problem? Thanks for any help. 回答1: (UPDATE: Thanks to comment by Louis Charette, this

Array_unique on a laravel eloquent collection

北慕城南 提交于 2019-12-06 18:20:17
问题 Not sure if this is possible but im trying to run array_unique over a collection of items i have, to remove duplicates. Although i cannot get it working. my controller logic: // init models $jobs = Job::search(); $countries = $jobs->get()->map(function( $job ) { return $job->country; }); $countries = array_unique( $countries->toArray() ); although this gets a "Array to string conversion" error 回答1: You can have unique values in your DB results using distinct or group by in your select clause.

How can I update data with Eloquent without id in Laravel 4

£可爱£侵袭症+ 提交于 2019-12-06 18:18:14
问题 When I want to update the FaqTrans database, but this datase have two primary key (faq_ida and lang) $table->primary(array('lang', 'faq_id')); . so I don't need a id column with auto_increment. However, when I use the following code to update the database, the error message hint me there is no id column. $faq_trans = FaqTrans::where('faq_id','=',$faq_id)->where('lang','=',$lang)->first(); $faq_trans->lang = Input::get('lang'); $faq_trans->body = Input::get('body'); $faq_trans->title = Input: