laravel-4

Laravel - Dynamic relationship using hasManyThough() and unique merge

佐手、 提交于 2020-01-05 03:05:14
问题 I can think of several ad-hoc ways to do this, but I'm really looking for a 'best practices' type of solution. I have 3 tables involved - users (user_id) - usages ('user_id', 'provider_id', 'nurse_id', 'patient_id') - usage_alerts ('usage_id') Im trying to eager load alerts using hasManyThrough() based on a user's role. The user_id field is agnostic, and can apply to any role, so merging and filtering needs to take place. Using $this->hasManyThrough('UsageAlert', 'Usage')->get() will return a

Laravel 4 - Select related models

匆匆过客 提交于 2020-01-04 14:31:19
问题 I have following table Schema::create('jokes_categories', function(Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('is_active'); $table->timestamps(); }); Schema::create('jokes', function(Blueprint $table) { $table->increments('id'); $table->string('content', 200)->unique();; $table->enum('is_active', array('Y', 'N')); $table->integer('category_id')->unsigned(); $table->foreign('category_id')->references('id')->on('jokes_categories'); $table->timestamps();

Laravel 4 - Select related models

霸气de小男生 提交于 2020-01-04 14:30:48
问题 I have following table Schema::create('jokes_categories', function(Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('is_active'); $table->timestamps(); }); Schema::create('jokes', function(Blueprint $table) { $table->increments('id'); $table->string('content', 200)->unique();; $table->enum('is_active', array('Y', 'N')); $table->integer('category_id')->unsigned(); $table->foreign('category_id')->references('id')->on('jokes_categories'); $table->timestamps();

Laravel file download response content type is text/html in localhost

不问归期 提交于 2020-01-04 11:42:01
问题 I try to return file download response in laravel with custom content type, the response content type comes as text/html to browser in localhost. Whereas it works fine in the server machine code. It makes debugging harder. Is it anything to do with apache server config? Below is the laravel code used. return Response::download($filepath, $filename.'_questionaire.csv', array( 'Content-Type' => 'text/csv', 'Content-Disposition' => 'attachment;filename="'.$filename.'._questionaire.csv"' )); 回答1:

Laravel 4 saving user into Database not working

岁酱吖の 提交于 2020-01-04 08:29:22
问题 I would like to save user's registration data into database, without email address each data has been saved successfully. I really don't know what is wrong with may code because i don't get any error or warning feedback message from Laravel. Here is my function public function doSignUp() { $rules = array( 'email' => 'required|email|unique:users', 'password' => 'required|confirmed|min:5', 'first_name' =>'required', 'last_name' =>'required', ); $messages = array( 'email.email' => 'Please enter

Laravel 4 saving user into Database not working

房东的猫 提交于 2020-01-04 08:28:08
问题 I would like to save user's registration data into database, without email address each data has been saved successfully. I really don't know what is wrong with may code because i don't get any error or warning feedback message from Laravel. Here is my function public function doSignUp() { $rules = array( 'email' => 'required|email|unique:users', 'password' => 'required|confirmed|min:5', 'first_name' =>'required', 'last_name' =>'required', ); $messages = array( 'email.email' => 'Please enter

How to add class to input field on error

谁说我不能喝 提交于 2020-01-04 05:52:05
问题 is there any chance in Laravel 4 to simply add a class e.g. "error" to a form field after validation error? I thought the Form Helper will do that... Thanks Regards 回答1: Yeah, you just have to check your errors for a certain error on a field when outputting the form field, and if it has an error, give it the class of error . I'm not sure of your variable names, but hopefully you get the idea... // Some validation $validator = Validate::make($input, $rules); // If it fails, pass errors into

Laravel 4 - Validator - File Size

六眼飞鱼酱① 提交于 2020-01-04 04:47:09
问题 Just a query about Laravels' validator. Users' of my site are going to be uploading files at times that are possibly going to be around the 100MB Mark. I've looked at : http://laravel.com/docs/4.2/validation My controller code is as follows : $rules = array( 'file' => 'max:102400' ); Is 102400 the equivalent of 100MB, I don't feel the docs are clear enough on this? 回答1: As described in the docs: max:value The field under validation must be less than or equal to a maximum value. Strings,

laravel 4 mockery mock model relationships

 ̄綄美尐妖づ 提交于 2020-01-04 02:50:21
问题 say I have two models that extend from Eloquent and they relate to each other. Can I mock the relationship? ie: class Track extends Eloquent { public function courses() { return $this->hasMany('Course'); } } class Course extends Eloquent { public function track() { return $this->belongsTo('Track'); } } in MyTest, I want to create a mock of course, and return an instance of track, by calling the track property, not the track instance ( I don't want the query builder ) use \Mockery as m; class

Laravel 4 Query Builder - groupBy Max Date

我的未来我决定 提交于 2020-01-04 02:00:12
问题 little query question, I have table: id | user_id | paper_update ------------------------------ 1 | 1 | 30-5-2011 2 | 2 | 30-5-2012 3 | 3 | 30-5-2012 4 | 1 | 30-5-2013 5 | 2 | 30-5-2013 6 | 3 | 30-5-2014 7 | 4 | 30-5-2014 8 | 5 | 30-5-2014 9 | 5 | 30-5-2015 10 | 5 | 30-5-2016 11 | 1 | 30-5-2010 ------------------------------- What I'm looking to do is to select only the records where paper_update is max between records with the same user_id , actually I want to group by the user_id in order