Instant response for OctoberCMS Flash messages combined with Romanov.Flashmessage plugin (no page reload)

$validation = Validator::make($data, $rules);
 if ($validation->fails()) {
     throw new ValidationException($validation);
 }
 try {
     $user = Auth::authenticate([
         'login' => array_get($data, 'login'),
         'password' => array_get($data, 'password')
     ], true);
 }
 catch (Exception $ex) {
     if (preg_match('/user was not found with the given cred/i',$ex->getMessage())) {
     $flash_message = 'A registered user was not found with that email';
 }
 elseif (preg_match('/hashed credential "password" did not match/i',$ex->getMessage())) {
     $flash_message = 'The password supplied for that user is incorrect';
 }
 }
 if ($flash_message) {
     return ['msgs' => [ 'danger' => $flash_message ], 'options' => [], 'settings' => [] ];
 }

 

This will replace the error message " user was found to match all plain text credentials however hashed credential "password" did not match." that comes by default with Laravel.

 

Source:

https://gist.github.com/kdallas/17e07f9b50b066a13bdd#file-account-php-L138

OctoberCMS debugging – DUMP() debug function for templating and Debugbar plugin

This is a very handy function for debugging the template.

reference: https://octobercms.com/docs/markup/function-dump

Usage:

{{ dump(user) }}
{{ dump(user, categories) }}
{{ dump() }}

It'll show you the variable type and its content, eg. if you have an object variable it'll show you the member functions or if you have a collection variable, it'll show you the keys and value types.

The following screenshot indicates the front-end output of an array variable:
octoberCMS dump function debug output screenshot for template front end

Here is another useful OctoberCMS plugin that'll help debugging as it could show much more information in the backend.

OctoberCMS DebugBar plugin

OctoberCMS debugbar plugin on GitHub: https://github.com/Flynsarmy/oc-debugbar-plugin

on OctoberCMS plugins page: https://octobercms.com/plugin/bedard-debugbar

A laravel validation rules – Check user age with laravel validation rules

Here is the example code for checking the age of an user.

Validator::extend('olderThan', function($attribute, $value, $parameters)
{
    $minAge = ( ! empty($parameters)) ? (int) $parameters[0] : 13;
    return (new DateTime)->diff(new DateTime($value))->y >= $minAge;

    // or the same using Carbon:
    // return Carbon\Carbon::now()->diff(new Carbon\Carbon($value))->y >= $minAge;
});

Usage:

$rules = ['dob' => 'olderThan']; // checks for 13 years as a default age
$rules = ['dob' => 'olderThan:15']; // checks for 15 years etc

Source:

http://stackoverflow.com/questions/23081654/check-age-with-laravel-validation-rules

Some of the jQuery / BootStrap Datepicker datetime input

Customizable Dropdown Birthday Picker Plugin with jQuery

This one's with 3 input fields.

http://www.jqueryscript.net/time-clock/Customizable-Dropdown-Birthday-Picker-Plugin-with-jQuery.html

Customizable Dropdown Birthday Picker Plugin with jQuery

Datepicker for Bootstrap

The best part for this one is the start and end date / check in and check out date control

http://www.eyecon.ro/bootstrap-datepicker/

Datepicker for Bootstrap

DateTime Picker Bootstrap - form component to handle date and time data.

http://www.malot.fr/bootstrap-datetimepicker/

DateTime Picker Bootstrap - form component to handle date and time data.

 

Pikaday A refreshing JavaScript Datepicker JS Lib

This is a simple yet fully functional datetime picker

Pikaday A refreshing JavaScript Datepicker

Link: https://github.com/dbushell/Pikaday

PHP date function: http://php.net/manual/en/function.date.php

I've found an issue when the instance is not bound to the filed value, eg. I'd like to preload the field value value="{{ SELF.userDob }}", this will cause the picker not work.

In order to solve this, try to bind the instance to the field value:

change the onSelect line

onSelect: function()

to

picker = new Pikaday({
    onSelect: function(date) {
        field.value = picker.toString();
    }

Then it should work.

Formatting Timestamps in Laravel and OctoberCMS

If you create a table with timestamp() via a migration, you'll actually get a timestamp that is matching the one created by date('Y-m-d H:i:s').

So in order to get the output correctly displayed with your local time format, or you'd like to format it and have an input to the database, then you'll need to format it before the output:

Created on: {{ date('F d, Y', strtotime($list->created_at)) }}

For formatting the input, eg. format a DOB datetime input:

$data = post();

$data['dob'] = date('Y-m-d H:i:s', post('dob'));

reference:  http://www.easylaravelbook.com/blog/2015/02/11/formatting-timestamps-in-laravel/