laravel-4

Laravel - is there a way to combine whereHas and with

只愿长相守 提交于 2020-01-02 08:31:07
问题 I'm currently facing a small problem. I want to return a model only if a relation with certain conditions exists. That's working fine with the whereHas()-method. $m = Model ::whereHas( 'programs', function($q) { $q->active(); } ); However, calling the relation as a property like this will give me all (not filtered results). $m->programs; So basically what I'm doing now is this: $m = Model ::whereHas( 'programs', function($q) { $q->active(); } ) ->with(array('programs' => function($q) { $q-

Restricting Laravel Error Log by IP Address

ε祈祈猫儿з 提交于 2020-01-02 07:57:52
问题 When debug is set to true in Laravel's app/config.php is there any way to restrict the resultant Whoops error page with stack trace to certain IP addresses, and IPs not on that list being shown a specific view? Thanks. 回答1: Not built in no. But you could probably implement this quite easily by capturing all exceptions and only re-throwing once you've compared the IP address of the user. So in app/start/global.php you'd need to configure the "Application Error Handler". At the moment it

Laravel 4 - How to use 'offset' in stead of 'page' with Eloquent's ->paginate()?

ε祈祈猫儿з 提交于 2020-01-02 07:39:39
问题 I am migrating an existing REST API to Laravel 4.1, and the API currently uses offset as querystring parameter to specify what the offset of the records needs to be. I would like to use the default Eloquent's paginate() , but these searches for the page querystring parameter. And of course it uses the page number (like 2) instead of the offset (like 200). Is there an easy way to configure the paginate function to this situation? Or do I need to use ->skip() and ->take() functions and make the

Parameterized query binding in ON clause for a LEFT JOIN in Laravel Eloquent / Query Builder

穿精又带淫゛_ 提交于 2020-01-02 06:41:09
问题 Let's say I want to show a full list of awards with type="color": Awards Type 2013 Winner ====== ==== =========== Blue Award color Tom Red Award color Green Award color Dan To achieve this result I could have a query in Laravel like this: $year = '2013'; $awards = DB::table('awards') ->leftJoin('winners', function($join) use ($year) { $join->on('awards.id','=','winners.award_id'); $join->on('winners.year','=',DB::raw("'".$year."'")); } ->where('awards.type','color') ->get(); If you output the

Is it possible add tinyInteger or smallInteger to increments on laravel ORM?

好久不见. 提交于 2020-01-02 06:15:10
问题 Is possible to add that code or something like that to laravel\Illuminate\Database\Schema\Blueprint to use with migrations? public function incrementsTiny($column) { return $this->unsignedTinyInteger($column, true); } public function incrementsSmall($column) { return $this->unsignedSmallInteger($column, true); } scenario: some temp table that don't grow high and have some useful information or just small table that do not have more than 100 lines and need some rare update (add or just change)

Laravel only validate items that are posted and ignore rest of validation array

这一生的挚爱 提交于 2020-01-02 05:34:13
问题 For a project with Laravel 4.1 I have a little UI issue I'd like to solve. Some inputs make an ajax call to laravel on blur and that works fine. It simply sends it's value. In laravel I then check with the validator. public function validate() { if(Request::ajax()) { $validation = Validator::make(Input::all(), array( 'email' => 'unique:users|required|email', 'username' => 'required' )); if($validation->fails()) { return $validation->messages()->toJson(); } return ""; } return ""; } Although

How to build a Laravel route that requires a specific URL query parameter?

孤人 提交于 2020-01-02 04:11:43
问题 Let's say I have URLs like this: localhost/ admin/users/ <--- Main Admin Users page localhost/ admin/users/?data=refresh <---- A typical ajax request made from that page And a simple controller like this: class UsersController extends Controller { public function index() // call some services // return a view } public function dataRefresh { // call some services // return some JSON } } And here's my routes.php I'm working on: Route::get('admin/users', array('as' => 'admin.users', 'uses' =>

How to make Laravel migrator work with namespaced migrations?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-02 02:46:07
问题 I namespaced my whole package successfully but I can not get namespaced migrations to work. In the autoload_classmap.php the migration classes are nicely namespaced, but the Migrator is not looking for the migration classes within the namespace. How to get the migrator to search for the migrations within the namespace? The migration file <?php namespace Atomend\Aeuser; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; use Schema, User; class UsersTable

Laravel - Artisan gives wrong base url

余生长醉 提交于 2020-01-02 02:35:10
问题 My app/config/app.php has 'url' => 'http://dev.domain.com/something/somethingElse' Then I have a function that can be called from the application and also from an artisan command. But URL::route('myRoute') returns different results. When called from the application it returns http://dev.domain.com/something/somethingElse/myRoute , but in the artisan command http://dev.domain.com/myRoute . URL::to has same behaviour. Note: I do not have any other app.php file defined for other environments

Populating a dropdown menu with database results in Laravel 4

丶灬走出姿态 提交于 2020-01-02 02:25:16
问题 I'm trying to populate a drop down menu with database results in Laravel 4. I'm extremely new to Laravel. This is actually my first site and I'm learning as I go. So, please tell me if I'm using the wrong terminology or not enough information. I've got a database of company info and I need users to be able to choose a company from a dropdown. Or if the company isn't in the database to add it. For the select menu, it needs to go like this: [company name result] And I'm using this code in my