laravel-4

Handling Laravel HttpException in Unit Testing

*爱你&永不变心* 提交于 2019-12-08 17:34:01
问题 One of my test functions for unit testing in Laravel keeps erroring out. I'm trying to assert that requesting a specific page without certain conditions being met triggers a 403 FORBIDDEN error. My test case function is this: public function testNoAjaxCall() { $this->call('POST', 'xyz', array()); $this->assertResponseStatus(403); } In the controller action this is routed to, I have this: if(!Input::has('ajax') || Input::get('ajax') != 1) { // Drop all 'non-ajax' requests. App::abort(403,

Laravel define a put/patch route as the same route name

瘦欲@ 提交于 2019-12-08 17:32:22
问题 In Laravel it's quite handy to quickly generate a load of routes by using a route resource: Route::resource('things'ThingsController'); This will produce all the necessary RESTful routes for CRUD operations. One of these is the PUT/PATCH route which might be defined as follows: PUT/PATCH things/{id} ThingsController@update things.update I've read around that it's better to explicitly define each of your routes rather than use a route resource but how would I define the PUT/PATCH route above.

Vagrant box: default: Warning: Connection timeout. Retrying

我与影子孤独终老i 提交于 2019-12-08 17:06:53
问题 I'm having trouble getting vagrant box running. I tried the solution in this thread: Vagrant stuck connection timeout retrying. No luck there. I also tried increasing the value of config.vm.boot_timeout. No luck either. Please help! $ vagrant destroy && vagrant up default: Are you sure you want to destroy the 'default' VM? [y/N] y ==> default: Forcing shutdown of VM... ==> default: Destroying VM and associated drives... ==> default: Running cleanup tasks for 'shell' provisioner... ==> default

Set autoincrement initial value in Laravel 4

放肆的年华 提交于 2019-12-08 17:05:18
问题 Is there a way to set the autoincrement initial value of the primary key on a table in Laravel 4 using Migrations with the Schema Builder? I want to set the id of a table to start at 100. I know that is possible using pure SQL with ALTER TABLE MY_TABLE AUTO_INCREMENT = 111111; , but I want to maintain database versioning with Laravel Migrations. Any idea? 回答1: I'm afraid Laravel still doesn't have a way to change autoincrement values, but you can create a migration and do in it: <?php use

Eloquent update() failing due to updated_at table ambiguity

给你一囗甜甜゛ 提交于 2019-12-08 16:29:16
问题 Ok, this question stems from a Laravel 4.1.23 install. I'm attempting to update multiple records using the Eloquent update() method on a query that includes a join: ChildSchoolYear::whereNull('exit_date')-> join('school_years', 'child_school_years.school_year_id','=','school_years.id')-> update(array('child_school_years.exit_date'=>'`school_years`.`end_date`', 'child_school_years.editor_id'=>$userId)) Laravel is generating the correct SQL for the query content I'm providing above, but the

laravel orderByRaw() on the query builder

浪尽此生 提交于 2019-12-08 15:27:14
问题 there is no way to make such a query( with the binding ) using the Laravel query builder right now: SELECT * FROM `posts` WHERE MATCH( `title`, `description` AGAINST( 'bar' IN BOOLEAN MODE)) ORDER BY (MATCH( 'title' AGAINST( 'bar' )) DESC; this will order the results by relevance, If we had(which we don't now!) orderByRaw then the above query would be: Post::whereRaw("MATCH( `title`, `description` AGAINST( ? IN BOOLEAN MODE))", array('bar'))->orderByRaw("(MATCH( 'title' AGAINST( ? )) DESC",

Laravel 4 - Get Current Route Name on Hidden Input to use for search

旧巷老猫 提交于 2019-12-08 15:00:50
问题 I have a search form in the nav bar on my Laravel 4 app. When someone types into search and submits I want the queries to only be performed based on what section of the site they are on. Example, if they are on the blog page, I want it to return only blog posts, and if they are on the users page, I want it to only bring up a list of users. Unless I'm missing something (certainly possibly as I'm new to Laravel!) I can do this using getCurrentRoute()->getPath(). But I have to do this from the

Incrementing dates with Carbon

空扰寡人 提交于 2019-12-08 14:57:56
问题 I'm trying to create an array of blackout dates for a reservation system in Laravel 4. There is one test row in my db with a start_date of 2016-01-24 and end_date of 2016-01-29. This is the code that pulls the row and loops through the dates using Carbon to increment by one day & add it to an array: $reserved = Reservation::where('property_id', $property->id)->get(); $blackoutDays = []; foreach($reserved as $r) { $start = new \Carbon\Carbon($r->start_date); $end = new \Carbon\Carbon($r->end

Export database (only data) with Laravel 4

谁说胖子不能爱 提交于 2019-12-08 14:44:52
I'm trying to find a package or method which allow me to export all the data from my database (SQL) in order to backup the database. The goal is to have a button to save the database in a SQL file and download it, so i need a method in a controller to export the data. I found nothing on http://packalyst.com/packages Is somebody knows a way to do that ? Thanks You can use this package - which is an excellent backup manager: https://github.com/heybigname/backup-manager If you want it to be accessible via a controller - you can just call the artisan command from your controller: function

Laravel Session Flash persists for 2 requests

巧了我就是萌 提交于 2019-12-08 14:33:46
问题 Recently I have changed to Laravel from Codeigniter, everything was going fine except I encountered a problem with Session::flash . when I create new user I get success message but It will persist for 2 requests, even I didn't pass the validator: my code in UsersController : function getCreateUser(){ $config = array( 'pageName' => 'createUser', 'pageTitle' => 'Create User', 'formUrl' => action('UsersController@postCreateUser'), 'modelFields' => array( array('db_name' => 'employee_id', 'text'