Thursday, December 29, 2022

Call Factory and make multiple record entry Using tinker

 $d = Factory(App\Department::class,3)->create();


> $d = Factory(App\Department::class, 10)->create();

= Illuminate\Database\Eloquent\Collection {#4478

    all: [

      App\Department {#4475

        name: "Gonzalo Walter Jr.",

        updated_at: "2022-12-29 16:17:43",

        created_at: "2022-12-29 16:17:43",

        id: 12,

      },

      App\Department {#4483

        name: "Felicia Lockman",

        updated_at: "2022-12-29 16:17:43",

        created_at: "2022-12-29 16:17:43",

        id: 13,

      },

      App\Department {#4481

        name: "Amelie O'Keefe",

        updated_at: "2022-12-29 16:17:43",

        created_at: "2022-12-29 16:17:43",

        id: 14,

      },

      App\Department {#4482

        name: "Dr. Theresia Gottlieb III",

        updated_at: "2022-12-29 16:17:43",

        created_at: "2022-12-29 16:17:43",

        id: 15,

      },

      App\Department {#4479

        name: "Ebony Douglas",

        updated_at: "2022-12-29 16:17:43",

        created_at: "2022-12-29 16:17:43",

        id: 16,

      },

      App\Department {#4477

        name: "Prof. Lillian Cummerata I",

        updated_at: "2022-12-29 16:17:43",

        created_at: "2022-12-29 16:17:43",

        id: 17,

      },

      App\Department {#4473

        name: "Lelia Thompson",

        updated_at: "2022-12-29 16:17:44",

        created_at: "2022-12-29 16:17:44",

        id: 18,

      },

      App\Department {#4474

        name: "Elza Kreiger",

        updated_at: "2022-12-29 16:17:44",

        created_at: "2022-12-29 16:17:44",

        id: 19,

      },

      App\Department {#4503

        name: "Brielle Lowe",

        updated_at: "2022-12-29 16:17:44",

        created_at: "2022-12-29 16:17:44",

        id: 20,

      },

      App\Department {#4500

        name: "Mr. Brenden West IV",

        updated_at: "2022-12-29 16:17:44",

        created_at: "2022-12-29 16:17:44",

        id: 21,

      },

    ],

  }







Sunday, October 30, 2022

how to use inker in laravel

Command : php artisan tinker





















get the value 

>>> $state = State::get();
[!] Aliasing 'State' to 'App\State' for this Tinker session.
=> Illuminate\Database\Eloquent\Collection {#4342
     all: [
       App\State {#4343
         id: 1,
         name: "jharkahand",
         created_at: "2022-10-30 04:28:11",
         updated_at: "2022-10-30 04:28:34",
       },
       App\State {#4344
         id: 2,
         name: "odisha",
         created_at: "2022-10-30 04:38:07",
         updated_at: "2022-10-30 04:38:07",
       },
       App\State {#4345
         id: 3,
         name: "bihar",
         created_at: "2022-10-30 04:38:32",
         updated_at: "2022-10-30 04:38:32",
       },
       App\State {#4346
         id: 4,
         name: "chattisgarh",
         created_at: "2022-10-30 04:39:25",
         updated_at: "2022-10-30 04:39:25",
       },
     ],
   }







create a record

 $state = State::create(['name'=>'maharastra']);
=> App\State {#4327
     name: "maharastra",
     updated_at: "2022-10-30 05:38:28",
     created_at: "2022-10-30 05:38:28",
     id: 5,
   }


or




>>> $state = new State
=> App\State {#4344}
>>> $state->name = 'west bengol';
=> "west bengol"
>>> $state->save();
=> true

check or find the entry by its id 
>>> $state = State::find(6);
=> App\State {#4333
     id: 6,
     name: "west bengol",
     created_at: "2022-10-30 05:40:15",
     updated_at: "2022-10-30 05:40:15",
   }


 







Friday, May 21, 2021

how to create model with the migration , seeder, factory , controller at same time ?

 Syntax : php artisan make:model ModelNmae .

This command will create a model with ModelName. During the model creation, we can create a seeder, factory, controller, migration for the model .

Syntax: PHP artisan make: model Profile --all 

for creating Migration only 

PHP artisan make: model Profile -m 

or 

PHP artisan make: model --migration 

similar way you can generate Factory 

PHP artisan make: model Profile -f

or 

PHP artisan make: model --factory

similar way you can generate Controller

PHP artisan make: model Profile -c

or 

PHP artisan make: model --controller

similar way you can generate ControllerSeeder

PHP artisan make model Profile -s

or 

PHP artisan make: model --seeder



Wednesday, May 19, 2021

Creating a Model In Laravel.

 Synatx : php artisan make:model ModelName 

Let's create a model for Product 

So we in the terminal write PHP artisan make: model Product 

















Writing a factory in Laravel.

By using the factory we can generate some fake data for the testing



<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */

use App\Product;
use Faker\Generator as Faker;

$factory->define(Product::classfunction (Faker $faker) {
    return [
        'name' => $faker->name// generate a random name 
        'brand'=>$faker->randomElement//generate a random elemtn
        'description'=> $faker->text// bunch of text
        'hsn'=> $faker->numberBetween($min = 1000$max = 9000), 
// number between 1000 -90000 to 9000
        'tax'=> $faker->randomElement(['18%','12%','5%','NILL','28%']) 
// pic a value from this array 
    ];
});.



Creating a factory in laravel

 Command: PHP artisan make: factory FactoryName

ex: PHP artisan make: factory ProductFactory  or you can make it during creating Model

PHP artisan make: model ModelName --all (it creates a model, controller, factory, seeder, and migration)

in this case, we are creating a factory for Product  so we put Product in the place of the model name

D:\www\crm (main)

λ php artisan make: factory RolesFactory --model=Role

Factory created successfully.

It generates a blank  factory file







Call Factory and make multiple record entry Using tinker

  $d = Factory(App\Department::class,3)->create(); > $d = Factory(App\Department::class, 10)->create(); = Illuminate\Database\Eloqu...