laravel-4

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

自古美人都是妖i 提交于 2019-12-05 17:44:01
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 this works, the json string also contains fields I have no need to check. To be precise this is the

How to make less to work with basset in laravel 4?

柔情痞子 提交于 2019-12-05 17:26:15
How to enable Less compiling with basset? My basset config file collection: 'collections' => array( 'application' => function($collection) { $collection->apply('UriRewriteFilter'); $directory = $collection->directory('../app/assets/stylesheets', function($collection) { $collection->add('less/design.less')->apply('Less'); }); $directory->apply('CssMin'); } ); Everything else in config is untouched. In the source code i get this: <link rel="stylesheet" type="text/css" href="http://localhost/Job/public/ph7mOzIaRTYLhvwL/application/6f5128120be8f13c4a2109051990f113/design.css" /> Even thought it's

Form::file: How to repopulate with Input::old After Validation Errors and/or on Update?

…衆ロ難τιáo~ 提交于 2019-12-05 16:29:48
In my PhotosController, I am trying to modify the edit action so that it shows the existing value in the Form::file() input field (and, so that it repopulates the field if validation fails). if ($validation->passes()) { // saves the image on the FS and updates the db entry } return Redirect::route('photos.edit') ->withInput(Input::all()) ->withErrors($validation) ->with('message', 'There were validation errors.'); The uploading process works fine, but when I view an existing record, or if validation fails upon creation, the Form::file doesn't show the value. I looked up the method in the api,

How to use update Resource Controllers laravel 4?

被刻印的时光 ゝ 提交于 2019-12-05 16:19:25
I have Customer Controller with index, edit, update methods Route::resource('customer', 'CustomerController'); Controller methods update public function update($id) { echo $id; } my HTML Form <form action="/customer/1" method="post"> <input type="text" name="email" value="" /> <input type="submit" value="" /> </form> I have following a Documentation here http://four.laravel.com/docs/controllers#resource-controllers PUT/PATCH /resource/{id} update It's seems not working for me, how to use it? thank you To use the PATH , PUT or DELETE HTML methods you need to add a hidden input with _method .

Laravel - How to use a vendor class?

余生颓废 提交于 2019-12-05 16:12:06
I want to use Mobile Detect on m routes.php file. I have added the package as a require in composer.json and it's installed in the vendor file. How can I use it now? I tried this answer and no luck because the class wasn't found: Laravel 4 using vendor classes { "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "require": { "laravel/framework": "4.2.*", "mobiledetect/mobiledetectlib": "*" }, "autoload": { "classmap": [ "app/commands", "app/controllers", "app/models", "app/database/migrations", "app/database/seeds", "app

Populate select element

梦想的初衷 提交于 2019-12-05 16:05:28
I want to populate a <select> element using the results from my categories table. In order to do that I use the following code. $catlist = Categories::where('type','=',$content_type) ->get(array('id','name'))->toArray(); The result structure is an array of rows. array 0 => array 'id' => int 1 'name' => string 'article' 1 => array 'id' => int 2 'name' => string 'news' A foreach statement surely would solve my problem but I'm looking for a better solution. You could use the lists(string $column [, string $key ]) method for this, found under "Retrieving A List Of Column Values" in the

Laravel save one to many relationship

╄→гoц情女王★ 提交于 2019-12-05 15:46:39
问题 I have the following relationships set up in Laravel: OrderStatus Model - hasMany('Order') Order Model - 'belongsTo('OrderStatus'); The database is set up with an orders table and an order_statuses table. The orders table has a field for order_status_id . When I save an Order, I manually set the order_status_id by fetching the appropriate Order Status model, like this: $status = OrderStatus::where(['name'=>'sample_status'])->firstOrFail(); $order->order_status_id = $status->id; $order->save()

laravel validate multiple models

柔情痞子 提交于 2019-12-05 15:46:03
I would like a best practice for this kind of problem I have items , categories and category_item table for a many to many relationship I have 2 models with these validations rules class Category extends Basemodel { public static $rules = array( 'name' => 'required|min:2|max:255' ); .... class Item extends BaseModel { public static $rules = array( 'title' => 'required|min:5|max:255', 'content' => 'required' ); .... class Basemodel extends Eloquent{ public static function validate($data){ return Validator::make($data, static::$rules); } } I don't know how to validate these 2 sets of rules from

Print JavaScript variable value inside a php tag using blade template in Laravel

情到浓时终转凉″ 提交于 2019-12-05 15:41:48
Suppose this is a JS code and I want to print the value of id . Here id is a variable with a value receiving into the jq function. function follow_or_unfollow(id,action){ myUrl = "{{ action('FollowsController@show', 'id') }}" ; } If we mension 'id' it will show the id string. PS. here {{ is using as it meant as php code in blade template. Now i need to print the script variable inside a php code. I am afraid that what you are asking is not possible. The simple reason being JavaScript is client-side and PHP is server-side. You can always place PHP code inside JavaScript because it will just be

Laravel mail bcc

时光毁灭记忆、已成空白 提交于 2019-12-05 14:57:54
问题 I am using the default Laravel Mail class to send emails. I am trying to add bcc to myself, but when I add a bcc the email is not send at all. Here is my code: Mail::send( 'emails.order.order', array( 'dateTime' => $dateTime, 'items' => $items ), function($message) use ($toEmail, $toName) { $message->from('my@email.com', 'My Company'); $message->to($toEmail, $toName); $message->bcc('mybcc@email.com'); $message->subject('New order'); } ); 回答1: I have found the problem. I didn't use the correct