laravel-4

Laravel force SSL gives 'This webpage has a redirect loop'

青春壹個敷衍的年華 提交于 2019-12-21 21:45:26
问题 I'm using Laravel 4.1, and want to force SSL site wide. My app is deployed on Heroku. Added this to either App::before or as a filter: if( ! Request::secure()) { return Redirect::secure(Request::path()); } But that gives me 'This webpage has a redirect loop' message. If I access some page by typing in https:// by hand, it serves that page correctly; but any link or form action is pointed to http:// , which I don't want. Also, I tried to add https parameter to some route, e.g.: Route::get(

Laravel 4: Nest view inside layout with data

回眸只為那壹抹淺笑 提交于 2019-12-21 21:36:43
问题 I'm writing a simple app which only relies on a few routes and views. I've setup an overall layout and successfully nested a template using the following. routes.php View::name('layouts.master', 'master'); $layout = View::of('master'); Route::get('/users', function() use ($layout) { $users = Users::all() return $layout->nest('content','list-template'); }); master.blade.php <h1>Template</h1> <?=$content?> list-template.php foreach($users as $user) { echo $user->title; } How do I pass the query

Behat 3 and Laravel, testing environment not being honoured

旧城冷巷雨未停 提交于 2019-12-21 21:35:46
问题 I am having a confusing problem using Behat 3 and Laravel to test an API. It seems that its not using the 'testing' environment database (in my case an sqlite memory database) ... but only some of the time. I've put a log message in the testing/database.php file to see when its loaded.. and I do see the log message when running Behat. But running the Behat features is adding rows to my development database - and some of my tests are failing for the same reason. My phpunit tests run fine and

Delete rows with Laravel query builder and LEFT JOIN

六眼飞鱼酱① 提交于 2019-12-21 20:54:16
问题 How to delete rows from multiple tables in one query (with left join). The query: DELETE `deadline`, `job` FROM `deadline` LEFT JOIN `job` .... So, I try it like this: DB::table('deadline', 'job') ->leftJoin('job', 'deadline.id', '=', 'job.deadline_id') ->where('deadline.id', $id) ->delete(); Seems that Laravel doesn't support delete from multiple tables with left join. Is there a supported way or workaround? 回答1: It seems that my way is not possible. So, I did it like this. $q = 'DELETE

Laravel 4: validate checkbox at least one

蹲街弑〆低调 提交于 2019-12-21 20:47:16
问题 I need to validate checkbox array: <input name="cats[]" type="checkbox" value="1"> sport <input name="cats[]" type="checkbox" value="2"> music <input name="cats[]" type="checkbox" value="3"> business I found "array" validation in documentation: Validator::make( [ 'cats' => Input::get('cats') ], [ 'cats' => 'array' ] ); Is there any built-in way to check if at least one item checked? Also, how to check if values submitted match a given list? 回答1: You can use min: value to validate a numeric

Laravel 4- redirect to a route inside javascript code Blade template

泄露秘密 提交于 2019-12-21 20:37:00
问题 I'm trying to write a simple redirection using javascript and blade engine, and this is an example of what i want to do: javascript code: <p>Click the button to go to the home page</p> <button onclick="myFunction()">Click me</button> <p id="demo"></p> <script> function myFunction() { var x; var r=confirm("Are you sure you want to leave this page ?"); if (r==true) { //Redirect to home } else { //stay here } document.getElementById("demo").innerHTML=x; } </script> when i use return Redirect:

Laravel Foreign Keys Drop-down List

南楼画角 提交于 2019-12-21 20:15:50
问题 I have 2 tables: CUSTOMERS(id, full_name, company_id) COMPANIES(id, company_name) I already created the relation between the two tables, and it's working fine because I can display company name in the customers view like this: $customer->company->company_name I'm now having issues with the customer create and edit views. I'd like to have the company_name as a drop-down (Form Select) in create and edit views. Then insert the company id to the CUSTOMERS table. 回答1: You need to supply Form:

Display Error Message for Custom Validation in Laravel 4

孤者浪人 提交于 2019-12-21 19:56:27
问题 I have created a custom error function by creating a class; <?php class CoreValidator extends Illuminate\Validation\Validator { public function validatePostcode($attribute, $value, $parameters = null) { $regex = "/^((GIR 0AA)|((([A-PR-UWYZ][0-9][0-9]?)|(([A-PR-UWYZ][A-HK-Y][0-9][0-9]?)|(([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY])))) [0-9][ABD-HJLNP-UW-Z]{2}))$/i"; if(preg_match($regex ,$value)) { return true; } return false; } } I reference it in my model; public

Laravel 4.2 Composer install error: “could not scan for classes”

隐身守侯 提交于 2019-12-21 19:52:26
问题 I want to install on my new Laravel 4.2 installation some packages via Composer. However, I am getting an exception. This is my Composer file: { "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "license": "MIT", "require": { "laravel/framework": "4.2.*", "zizaco/confide": "~4.0@dev", "zizaco/entrust": "1.2.*@dev", "barryvdh/laravel-ide-helper": "1.*", "fzaninotto/faker": "1.3.*@dev", "bllim/datatables": "~1.3",

Why is my debug data unformatted?

╄→гoц情女王★ 提交于 2019-12-21 18:47:31
问题 var_dump and print_r are displayed are not formatted when using Laravel 4. How do I format the data to be more readable? 回答1: Add Kint to your composer.json by running this on the command line: composer require raveren/kint "dev-master" And then try it: dd( new Controller ); You should see this: Better, huh? 回答2: Use kint we use should s() instead of print_r() use should d() instead of var_dump() ex: sd($arr); like same print_r($arr); die(); Ref: http://raveren.github.io/kint/#configuration