Laravel Code

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

//$DB = new DB( 'mysql:host='.DATABASE_HOST.'; dbname='.DATABASE_NAME.

';
charset=utf8',DATABASE_USER,DATABASE_PASSWORD);
// $DB->setFetchMode(PDO::FETCH_ASSOC);
// $db = new
PDO('mysql:host='.DATABASE_HOST.';dbname='.DATABASE_NAME.';charset=utf8',
DATABASE_USER, DATABASE_PASSWORD);

###################################
<?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;

class blogsTableSeeder extends Seeder


{

private function dateAleatoire()


{
return Carbon::createFromDate(null, rand(1, 12), rand(1, 28));
}

/**
* Run the database seeds.
*
* @return void
*/
public function run()
{

DB::table('blogs')->delete();

$faker = Faker\Factory::create();

for($i = 0; $i < 20; ++$i)


{
$date = $this->dateAleatoire();

DB::table('blogs')->insert([
'titre' => $faker->text(50),
'texte' => $faker->text,
'created_at' => $date,
'updated_at' => $date
]);
}
}

###########################

<?php

use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// $this->call(UserTableSeeder::class);
$this->call(blogsTableSeeder::class);
}
}

###########################
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateBlogsTable extends Migration


{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('blogs', function (Blueprint $table) {
$table->increments('id');
$table->string('titre');
$table->text('texte');
$table->timestamps();
});

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::drop('blogs');
}
}

########################
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Blog extends Model


{
//
protected $fillable=['titre', 'texte'];
}

<link rel="stylesheet" href="{{ asset('resources/css/bootstrap.min.css') }}">

<script src="/resources/js/bootstrap.js"></script>

You might also like