Showing posts with label Example. Show all posts
Showing posts with label Example. Show all posts

Thursday, August 4, 2016

eloquent relationships -- hasOne

1. create public function shape with hasOne relationships
class Member extends Model

    public function shape()
    {
       return $this->hasOne('App\Shape','part_id','part_id');
    }

2. Example with App\Member::with('shape')->find(1);
>>> App\Member::with('shape')->find(1);
=> App\Member {#751
     id: 1,
     part_id: "4882557",
     surname: "KRISHNAN",
     firstname: "KUMARESAN",
     email: "kumar@aeonmalaysia.com.my",
     created_at: "2016-08-04 10:19:56",
     updated_at: "2016-08-04 10:19:56",
     shape: App\Shape {#756
       id: 1,
       part_id: "4882557",
       match_score: "4.00",
       scales_num: "2.00",
       scales_cls: "22.00",
       created_at: "2016-08-04 10:20:05",
       updated_at: "2016-08-04 10:20:05",
     },
   }
>>>

Wednesday, August 3, 2016

flash implementation

1. Reference
https://github.com/laracasts/flash

2. Installation
a. Run composer require laracasts/flash
b. And then, if using Laravel 5, include the service provider within config/app.php.

'providers' => [
    Laracasts\Flash\FlashServiceProvider::class,
];

3.Usage
a. Within your controllers, before you perform a redirect...

public function store()
{
    flash('Welcome Aboard!');

    return home();
}

b. Add include flash message on view.
@include('flash::message')

<!-- This is only necessary if you do Flash::overlay('...') -->
<script src="//code.jquery.com/jquery.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>
    $('#flash-overlay-modal').modal();
</script>

Thursday, July 28, 2016

factory faker

factory faker step by step.

1. Add $factory on ModelFactory.php
$factory->define(App\Tenant::class, function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'nric' => $faker->numerify('######-##-####'),
        'dob' => $faker->date
    ];
});

2. run with php artisan tinker
 factory('App\Tenant',20)->create();

3. Reference.
https://github.com/fzaninotto/Faker

CMS link

1. MicroweberCMS Drag and Drop CMS and online shop
https://microweber.com/ 

laravel highchart

Sunday, July 17, 2016

appzcoder crud-generator


1.url
https://packagist.org/packages/appzcoder/crud-generator

2. Crud command: .
php artisan crud:generate Posts --fields="title#string, body#text"
 
3. You can also easily include route, set primary key, set views directory etc 
through options --route, --pk, --view-path as belows: 
php artisan crud:generate Posts --fields="title#string#required, 
body#text#required_with:title|alpha_num" --route=yes --pk=id 
--view-path="admin" --namespace=Admin --route-group=admin 
 
3. These fields are supported for migration and view's form:
  • string
  • char
  • varchar
  • password
  • email
  • date
  • datetime
  • time
  • timestamp
  • text
  • mediumtext
  • longtext
  • json
  • jsonb
  • binary
  • number
  • integer
  • bigint
  • mediumint
  • tinyint
  • smallint
  • boolean
  • decimal
  • double
  • float
  • enum
 

Tuesday, June 28, 2016

Example str_slug

$str = "this is a test";
$slug = str_slug($str);
var_dump("slug=" .$slug);
$slug2 = $slug . "-2";
var_dump("slug2=" .$slug2);

$pieces = explode("-",$slug2);

$number = intval(end($pieces));

var_dump("number=" .$number);