Skip to content

Commit

Permalink
create factory for user and news
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil committed Dec 12, 2022
1 parent b0ff9fc commit 8dd9205
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class News extends Model
{
protected $table = 'newss';

use HasFactory;

protected $fillable = [
'title', 'content',
];
Expand Down
2 changes: 2 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class User extends Authenticatable
{
use Notifiable;
use HasFactory;

/**
* The attributes that are mass assignable.
Expand Down
35 changes: 35 additions & 0 deletions database/factories/NewsFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Database\Factories;

use App\News;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\News>
*/
class NewsFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = News::class;

/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'title' => $this->faker->text,
'content' => $this->faker->paragraph($nbSentences = 5, $variableNbSentences = true),
'user_id' => 1,
'client_id' => 1
];
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<?php
namespace Database\Factories;

use App\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;

/**
* Define the model's default state.
*
Expand Down

0 comments on commit 8dd9205

Please sign in to comment.