allowedMilliseconds
with value 100
pm.environment.set("allowedMilliseconds", 100);
Get the environment variablepm.environment.get("allowedMilliseconds")
The environment variable in real use case. In this example response time is checked to be below 100mspm.test("Response time is less than "+pm.environment.get("allowedMilliseconds")+"ms", function () {
pm.expect(pm.response.responseTime).to.be.below(pm.environment.get("allowedMilliseconds"));
});
allowedMilliseconds
with value 100
pm.global.set("allowedMilliseconds", 100);
Get the global variablepm.global.get("allowedMilliseconds")
The global variable in real use case. In this example response time is checked to be below 100mspm.test("Response time is less than "+pm.global.get("allowedMilliseconds")+"ms", function () {
pm.expect(pm.response.responseTime).to.be.below(pm.global.get("allowedMilliseconds"));
});
forget
about test.php
that was tracked but is now in .gitignore
git rm --cached test.php
The command makes Git forget
about all files under docs
directory that was tracked but is now in .gitignore
git rm -r --cached docs/
# Generate a model and a FlightFactory class...
php artisan make:model Flight --factory
php artisan make:model Flight -f
# Generate a model and a FlightSeeder class...
php artisan make:model Flight --seed
php artisan make:model Flight -s
# Generate a model and a FlightController class...
php artisan make:model Flight --controller
php artisan make:model Flight -c
# Generate a model and a migration, factory, seeder, and controller...
php artisan make:model Flight -mfsc
php artisan make:factory BookFactory --model=Book
.it would generate a BookFactory.php
file under database/factories
which looks like so.
<?php
namespace Database\Factories;
use App\Models\Book;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class BookFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Book::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
//
];
}
}
define the definition method like so.
public function definition()
{
return [
'title' => $this->faker->name,
'author' => $this->faker->name,
'published' => 1
];
}
Using the factories
Once the BookFactory
is created, it’s now ready to be used. For instance, we can use it in the database/seeders/DatabaseSeeder.php
class like so.
<?php
namespace Database\Seeders;
use App\Models\Book;
use App\Models\User;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
Book::factory(5)->create();
}
}
Notice, you can now directly use the factory on the model instance (App\Models\Book in this case) that is because when you create a model using the php artisan make:model Book
Artisan command in Laravel 8, it generates the model which includes the new HasFactory
trait. So, our Book model looks like so.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Book extends Model
{
use HasFactory;
}
laravel 8 version
php artisan tinker
User::factory()->count(5)->create()
laravel 6, 7 version
php artisan tinker
factory(App\User::class,5)->create();
This by default created factory of laravel. you can also see that on following url: database/factories/UserFactory.php
.<form action="" method="get">
<fieldset>
<legend>Personal info:</legend>
<label for="first_name">first name:</label><input type="text" name="first_name" id="first_name"><br/>
<label>last name:</label><input type="text" name="last_name"><br/>
</fieldset>
<br/>
<fieldset>
<legend>Hobbies:</legend>
<label>sport</label><input type="checkbox" value="sport">
<label>sport</label><input type="checkbox" value="gaming">
</fieldset>
<br/>
<input type="submit" value="submit">
</form>
<form action="" method="get">
Name:<input type="text" name="name"><br/>
Password:<input type="password" name="password"><br/>
CheckBoxes:<br/>
1<input type="checkbox" value="2" name="checker">
2<input type="checkbox" value="2" name="checker">
<br/>
<input type="file"/><br/>
<input type="submit" value="submit"><br/>
<input type="reset" value="reset">
</form>
<form action="" method="get">
What do you do?:
<textarea name="story"></textarea>
</form>