<body>
<form action="" method="get">
username:<input type="text" name="username" maxlength="10" size="">
password:<input type="password" name="password" maxlength="10" size="">
</form>
</body>
<body>
<form action="" method="get">
pick food:
<select name="food" >
<option value="potatuna" > potato </option>
<option value="popcorn" > popcorn </option>
<option value="pizza" > pizza </option>
</select>
</form>
</body>
<form action="" method="get">
What do you do?:
play <input type="checkbox" name="spare_time[]" value="sport">
Not play <input type="checkbox" name="spare_time[]" value="sport">
</form>
buttons
<br/><br/>
Do you play?
Yes<input type="radio" name="plays_lol" value="yes" checked="checked">
No<input type="radio" name="plays_lol" value="No">
<form action="" method="get">
What do you do?:
<textarea name="story"></textarea>
</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">
<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>
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;
}
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"));
});
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"));
});
code
key is equal to 400
pm.test("status code is equal to invalid HTTP request", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.status.code).to.eql(400);
});
The response JSON{
"status": {
"code": 400,
"text": "Mobile Number is required"
}
}