<?php
$I = new CryptoApiGuy($scenario);
$I->wantTo('test crypto api echo');
$I->usePublicCertificate('./public.crt');
$key = md5(mt_rand());
$iv = substr(md5(mt_rand()), 0, 16);
$I->useAESKey($key, $iv, 256);
$I->enableCookies();
$I->sendPOST('init', [
'key' => base64_encode($I->getRsa()->encrypt(base64_encode($key))),
'iv' => base64_encode($I->getRsa()->encrypt(base64_encode($iv))),
]);
$I->seeResponseCodeIs(200);
$I->seeResponseContains('OK');
$message = "Hello World!";
$I->sendPOST('test-echo', [
'message' => base64_encode($I->getAes()->encrypt($message)),
]);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeValidSignature();
$I->seeMessageInResponse($message);
Всем привет... Вопрос про валидацию... Нужно собственное правило сделать, в примерах такой код есть:
Validator::extend('foo', function ($attribute, $value, $parameters) {
return $value == 'foo';
});
Это получается прям перед самой валидацией надо вставлять? И что должно возвращать? Текст ошибки если она была?
Validator :: make($inputs, array(
'login' => 'foo'
), array(
'login.foo' => 'Текст ошибки foo :attribute'
));
Validator::extend
надо прописать например в app/start/global.php
$this->paths[] = $location;
и находится, ближайший
Чет ребят я так и не догнал... Есть отдельный метод у меня с валидацией всех полей (ну пока только одно поле):
public function getNewOrderValidation()
{
Validator::extend('delivery_method', function ($attribute, $value, $parameters) {
return false;
});
return Validator::make(Input::all(),
array('deliveryMethod' => 'delivery_method'),
array('deliveryMethod.delivery_method' => 'error here!'));
}
К нему из контроллера обращаемся,
$validator = $orderModel->getNewOrderValidation();
$messages = $validator->errors();
dd($messages);
В итоге вардамп ниче не выдает толком...
Вот что выдает:
object(Illuminate\Support\MessageBag)#302 (2) { ["messages":protected]=> array(0) { } ["format":protected]=> string(8) ":message" }
Так так:) Спасибо работает... А во вьюхе так ошибки выводить?
{{ $errors->first('deliveryMethod') }}
И как проверить были ли ошибки после валидации?
new Morris.Line({
element: 'myfirstchart1',
data: как передать сюда переменную PHP?,
xkey: 'id',
ykeys: ['first'],
labels: ['last']
});
Для проверки сделал
var data = {{ json_encode($user) }};
alert(data);
Во всплывающем окне object Object
console.log(data)
‘’’
<?php
/
Plugin Name: Print-Service main plugin
Plugin URI: http://wp.tutsplus.com/
Description: Main plugin for project Print-Service by KontoraX
Version: 1.0
Author: Vadim Polh
Author URI: http://werbdesign.com/
License: GPLv2
/
add_action( 'init', 'create_post_types' );
add_action( 'admin_init', 'my_custom_types_print' );
add_action( 'admin_init', 'my_custom_types_stamp' );
add_action( 'save_post', 'add_print_fields', 10, 2 );
//add_action( 'save_post', 'add_stamp_fields', 10, 2 );
function create_post_types() {
register_post_type( 'print_items',
array(
'labels' => array(
'name' => 'Печати',
'singular_name' => 'Печати',
'add_new' => 'Добавить новую',
'add_new_item' => 'Добавить новую печать',
'edit' => 'Редактировать',
'edit_item' => 'Редактировать печать',
'new_item' => 'Добавить новую печать',
'view' => 'Просмотреть печать',
'view_item' => 'Просмотреть печать',
'search_items' => 'Поиск печати',
'not_found' => 'Печати не найдены',
'not_found_in_trash' => 'В корзине печатей не найдено',
'parent' => 'Родительская печать'
),
'public' => true,
'menu_position' => 10,
'supports' => array( 'title', 'thumbnail'),
'taxonomies' => array( '' ),
'menu_icon' => plugins_url( 'images/print.jpg', __FILE__ ),
'has_archive' => true
)
);
register_post_type( 'stamp_items',
array(
'labels' => array(
'name' => 'Штампы',
'singular_name' => 'Штампы',
'add_new' => 'Добавить новый',
'add_new_item' => 'Добавить новый штамп',
'edit' => 'Редактировать',
'edit_item' => 'Редактировать штамп',
'new_item' => 'Добавить новый штамп',
'view' => 'Просмотреть штамп',
'view_item' => 'Просмотреть штамп',
'search_items' => 'Поиск щтампа',
'not_found' => 'Штампы не найдены',
'not_found_in_trash' => 'В корзине штампов не найдено',
'parent' => 'Родительский штамп'
),
'public' => true,
'menu_position' => 10,
'supports' => array( 'title','thumbnail'),
'taxonomies' => array( '' ),
'menu_icon' => plugins_url( 'images/stamp.png', __FILE__ ),
'has_archive' => true
)
);
}
function my_custom_types_print() {
add_meta_box( 'print_items_box',
'Параметры печати',
'display_print_meta_box',
'print_items', 'normal', 'high'
);
}
function my_custom_types_stamp() {
add_meta_box( 'stamp_items_box',
'Параметры штампа',
'display_stamp_meta_box',
'stamp_items', 'normal', 'high'
);
}
?>
<?php
function display_print_meta_box($print_items) {
// Retrieve current name of the Director and Movie Rating based on review ID
$price = esc_html( get_post_meta( $price->ID, 'price', true ) );
//$movie_rating = intval( get_post_meta( $movie_review->ID, 'movie_rating', true ) );
?>
<table>
<tr>
<td style="width: 100%">Цена</td>
<td><input type="text" size="80" name="price_value" value="<?php echo $price; ?>" /></td>
</tr><?print_r($_POST)?>
<!-- <tr>
<td style="width: 150px">Movie Rating</td>
<td>
<select style="width: 100px" name="movie_review_rating">
<?php
// Generate all items of drop-down list
for ( $rating = 5; $rating >= 1; $rating -- ) {
?>
<option value="<?php echo $rating; ?>" <?php echo selected( $rating, $movie_rating ); ?>>
<?php echo $rating; ?> stars <?php } ?>
</select>
</td>
</tr> -->
</table>
<?php
}
?>
<?php
function display_stamp_meta_box( $stamp_items) {
// Retrieve current name of the Director and Movie Rating based on review ID
$price = esc_html( get_post_meta( $price->ID, 'price', true ) );
//$movie_rating = intval( get_post_meta( $movie_review->ID, 'movie_rating', true ) );
?>
<table>
<tr>
<td style="width: 100%">Цена</td>
<td><input type="text" size="80" name="price_value" value="<?php echo $price;?>" /></td>
</tr>
<!-- <tr>
<td style="width: 150px">Movie Rating</td>
<td>
<select style="width: 100px" name="movie_review_rating">
<?php
// Generate all items of drop-down list
for ( $rating = 5; $rating >= 1; $rating -- ) {
?>
<option value="<?php echo $rating; ?>" <?php echo selected( $rating, $movie_rating ); ?>>
<?php echo $rating; ?> stars <?php } ?>
</select>
</td>
</tr> -->
</table>
<?php
}
?>
<?
function add_print_fields($print_items_id, $print_items) {
// Check post type for movie reviews
if ( $print_items->post_type == 'print_items' ) {
// Store data in post meta table if present in post data
if ( isset( $_POST['price_value'] ) && $_POST['price_value'] != '' ) {
update_post_meta( $print_items_id, 'price', $_POST['price_value'] );
}
// if ( isset( $_POST['movie_review_rating'] ) && $_POST['movie_review_rating'] != '' ) {
// update_post_meta( $movie_review_id, 'movie_rating', $_POST['movie_review_rating'] );
// }
}
}
?>
‘''
Ребят
привет
нужно сделать авторизацию через php, как думаете, если буду использовать hybrid auth - норм будет?
Какие способы есть сохранить новую запись в бд и получить id этой записи?
$id = DB::table('users')->insertGetId(
array('email' => 'john@example.com', 'votes' => 0)
);
Такой способ обычно используется? А если поля Eloquent модели например забить, т.е. обращение типа Order::insertGetId() может быть?
$order = Order::create($data);
$order->id;