/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); // $this->call('UserTableSeeder'); User::truncate(); App\Models\Article::truncate(); // App\Models\Category::truncate(); // factory(User::class, 47)->create()->each(function($u) { // $n = rand(1,30); // // dd($u); // $u->articles()->save(factory(App\Models\Article::class, $n)->make()); // }); $users = factory(App\Models\User::class, 13)->create()->each(function ($u) { $n = rand(1, 30); for ($i = 1; $i < $n; $i++) { $u->articles()->save(factory(App\Models\Article::class)->make()); } }); // factory(App\Models\Article::class, 54)->create(); factory(App\Models\Category::class, 20)->create(); // factory(App\Mo/usdels\Comment::class, 98)->create(); // factory(App\Models\Notification::class, 12)->create(); Model::reguard(); }
function article(string $technicalName) : App\Models\Article { return App\Models\Article::findByTechnicalName($technicalName); }
@extends((Auth::check() && !Auth::user()->isBuyer()) ? 'layouts.'.$user->role->name : 'layouts.front') @section('title', 'Viewing All Articles') @section('content') <div class="container"> <div class="row"> <div class="headline"> <h2>All Articles</h2> </div><!-- headline --> @include('articles.sidebar') <div class="col-sm-12 col-md-9 col-lg-9"> <?php $articles = App\Models\Article::paginate(24); ?> @foreach($articles as $a) <div class="col-md-6 col-lg-4 col-xs-12"> <div class="media"> <a class="pull-left" href="{{ url('articles/'.$a->slug) }}"> <img class="media-object" src="{{ $a->featuredImage }}" height="84" width="84"> </a> <div class="media-body"> <a href="{{ url('articles/'.$a->slug) }}"> <h6 class="media-heading">{{ $a->title }}</h6> </a> <!-- Nested media object --> <div class="media"> {{ Str::limit(strip_tags($a->html), 80) }} </div> </div>
<?php $articles = App\Models\Article::recent(1); ?> <div class="the-box no-border"> <h4 class="small-heading more-margin-bottom">RECENT POSTS</h4> <ul class="media-list media-xs media-dotted"> @foreach($articles as $article) <li class="media"> <div class="media-body"> <h4 class="media-heading"><a href="/article/{{ $article->id }}">{{ $article->title }}</a></h4> <p class="date"><small>{{ date('M d , Y @ h A', strtotime($article->published_at)) }}</small></p> </div> </li> @endforeach </ul> </div><!-- /.the-box .no-border -->
<?php require __DIR__ . '/../autoload.php'; $article = new \App\Models\Article(); assert($article->isNew()); $article->title = 'Новость №1'; assert($article->save()); assert(!$article->isNew()); $article->title = 'Новость №2'; assert($article->save()); assert($article->delete()); assert($article->isDeleted()); assert(!$article->isNew()); assert(!$article->save()); assert(!$article->delete());
return ['name' => $faker->firstName, 'surname' => $faker->lastName, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10), 'profileimage' => substr(str_replace(storage_path(), '', $faker->image(storage_path(), 640, 480, 'people')), 1)]; }); $factory->define(App\Models\Article::class, function (Faker\Generator $faker) { return ['title' => $faker->sentence, 'user_id' => App\Models\User::all()->random()->id, 'text' => $faker->text(800)]; }); $factory->defineAs(App\Models\Article::class, 'withTask', function (Faker\Generator $faker) use($factory) { $article = $factory->raw(App\Models\Article::class); return array_merge($article, ['task_id' => App\Models\Task::all()->random()->id]); }); $factory->defineAs(App\Models\Article::class, 'published', function (Faker\Generator $faker) use($factory) { $article = $factory->raw(App\Models\Article::class); return array_merge($article, ['state' => \App\Models\Article::PUBLISHED]); }); $factory->define(App\Models\Tag::class, function (Faker\Generator $faker) { return ['name' => $faker->word]; }); $factory->define(App\Models\ArticleTagMapper::class, function (Faker\Generator $faker) { return ['article_id' => App\Models\Article::all()->random()->id, 'tag_id' => App\Models\Tag::all()->random()->id]; }); $factory->define(App\Models\Course::class, function (Faker\Generator $faker) { return ['name' => $faker->word, 'year' => $faker->year, 'user_id' => App\Models\User::all()->random()->id]; }); $factory->define(App\Models\Task::class, function (Faker\Generator $faker) { return ['name' => $faker->word, 'course_id' => App\Models\Course::all()->random()->id]; }); $factory->define(App\Models\Discussion::class, function (Faker\Generator $faker) { return ['user_id' => App\Models\User::all()->random()->id, 'text' => $faker->text($faker->numberBetween(100, 400)), 'article_id' => App\Models\Article::all()->random()->id, 'parent' => $faker->boolean(70) && App\Models\Discussion::all()->count() > 0 ? App\Models\Discussion::all()->random()->id : null]; }); $factory->define(App\Models\Rating::class, function (Faker\Generator $faker) { return ['user_id' => App\Models\User::all()->random()->id, 'article_id' => App\Models\Article::all()->random()->id, 'rating' => $faker->numberBetween(1, 5)]; });
<?php $comments = App\Models\Article::comments(1); ?> <div class="the-box no-border"> <h4 class="small-heading more-margin-bottom">RECENT COMMENTS</h4> <ul class="media-list media-xs media-dotted"> @foreach($comments as $comment) <li class="media"> <a class="pull-left" href="#fakelink"> <img class="media-object" src="{{ asset('/img/avatar/avatar.jpg') }}" alt="Avatar"> </a> <div class="media-body"> <h4 class="media-heading"><a href="#fakelink">{{ $comment->written_by }}</a> at <a href="/article/{{ $comment->referer_article }}">{{ $comment->article_title }}</a></h4> <p class="date"><small>{{ date('M d, h:i:s A', strtotime($comment->created_at)) }}</small></p> <p class="small">{{ $comment->body }}</p> </div> </li> @endforeach </ul> </div><!-- /.the-box .no-border -->