Skip to content

Commit

Permalink
Merge branch 'blog-mvp' of https://github.com/SethSharp/Portfolio int…
Browse files Browse the repository at this point in the history
…o blog-mvp
  • Loading branch information
SethSharp committed Jan 25, 2024
2 parents 572bfbc + 68c4bd5 commit a1fadb3
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 35 deletions.
28 changes: 28 additions & 0 deletions app/Domain/Blog/Models/Blog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Domain\Blog\Models;

use App\Domain\Iam\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Blog extends Model
{
use HasFactory;

const STATUS_DRAFT = 'draft';
const STATUS_PUBLISHED = 'published';
const STATUS_DELETED = 'deleted';

public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'author_id');
}

public function tags(): BelongsToMany
{
return $this->belongsToMany(Tag::class)->withTimestamps();
}
}
17 changes: 17 additions & 0 deletions app/Domain/Blog/Models/Tag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Domain\Blog\Models;

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

class Tag extends Model
{
use HasFactory;

public function blogs(): BelongsToMany
{
return $this->belongsToMany(Blog::class)->withTimestamps();
}
}
28 changes: 11 additions & 17 deletions app/Models/User.php → app/Domain/Iam/Models/User.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
<?php

namespace App\Models;
namespace App\Domain\Iam\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Domain\Blog\Models\Blog;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
use HasApiTokens;
use HasFactory;
use Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];

public function blog(): HasMany
{
return $this->hasMany(Blog::class);
}
}
18 changes: 18 additions & 0 deletions app/Http/Controllers/Blogs/IndexBlogsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Controllers\Blogs;

use App\Domain\Blog\Models\Blog;
use Inertia\Inertia;
use App\Http\Controllers\Controller;
use Inertia\Response;

class IndexBlogsController extends Controller
{
public function __invoke(): Response
{
return Inertia::render('Blogs/Index', [
'blogs' => Blog::all()
]);
}
}
14 changes: 14 additions & 0 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Http\Controllers;

use Inertia\Inertia;
use Inertia\Response;

class DashboardController extends Controller
{
public function __invoke(): Response
{
return Inertia::render('Dashboard');
}
}
14 changes: 14 additions & 0 deletions app/Http/Controllers/Views/ShowBlogsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Http\Controllers\Views;

use Illuminate\View\View;
use App\Http\Controllers\Controller;

class ShowBlogsController extends Controller
{
public function __invoke(): View
{
return view('blogs');
}
}
2 changes: 1 addition & 1 deletion config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
'model' => \App\Domain\Iam\Models\User::class,
],

// 'users' => [
Expand Down
27 changes: 27 additions & 0 deletions database/factories/Domain/Blog/Models/BlogFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Database\Factories\Domain\Blog\Models;

use Illuminate\Support\Str;
use App\Domain\Iam\Models\User;
use App\Domain\Blog\Models\Blog;
use Illuminate\Database\Eloquent\Factories\Factory;

class BlogFactory extends Factory
{
protected $model = Blog::class;

public function definition()
{
$name = fake()->name();
$slug = Str::slug($name);

return [
'author_id' => User::factory()->create()->id,
'title' => $name,
'slug' => $slug,
'content' => fake()->text(),
'status' => Blog::STATUS_DRAFT
];
}
}
18 changes: 18 additions & 0 deletions database/factories/Domain/Blog/Models/TagFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Database\Factories\Domain\Blog\Models;

use App\Domain\Blog\Models\Tag;
use Illuminate\Database\Eloquent\Factories\Factory;

class TagFactory extends Factory
{
protected $model = Tag::class;

public function definition()
{
return [
'name' => 'Tutorial',
];
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<?php

namespace Database\Factories;
namespace Database\Factories\Domain\Iam\Models;

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

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
*/
class UserFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
protected $model = User::class;

public function definition()
{
return [
Expand All @@ -26,11 +21,6 @@ public function definition()
];
}

/**
* Indicate that the model's email address should be unverified.
*
* @return static
*/
public function unverified()
{
return $this->state(function (array $attributes) {
Expand Down
25 changes: 25 additions & 0 deletions database/migrations/2024_01_24_014509_create_blogs_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

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

return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('blogs', function (Blueprint $table) {
$table->id();
$table->foreignId('author_id');
$table->string('title');
$table->string('slug');
$table->text('content');
$table->string('status');
$table->timestamps();
});
}
};
31 changes: 31 additions & 0 deletions database/migrations/2024_01_24_014627_create_tags_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

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

return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tags', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('tags');
}
};
22 changes: 22 additions & 0 deletions database/migrations/2024_01_24_014650_create_blog_tag_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

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

return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('blog_tag', function (Blueprint $table) {
$table->id();
$table->foreignId('tag_id');
$table->foreignId('blog_id');
$table->timestamps();
});
}
};
10 changes: 7 additions & 3 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Database\Seeders;

// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use App\Models\User;
use App\Domain\Iam\Models\User;
use Illuminate\Database\Seeder;
use App\Domain\Blog\Models\Blog;
use Illuminate\Support\Facades\Hash;

class DatabaseSeeder extends Seeder
Expand All @@ -16,10 +16,14 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
User::factory()->create([
$admin = User::factory()->create([
'name' => 'Admin',
'email' => '[email protected]',
'password' => Hash::make('123456')
]);

Blog::factory()->create([
'author_id' => $admin->id
]);
}
}
12 changes: 12 additions & 0 deletions resources/js/Pages/Blogs/Index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script setup>
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout.vue";
import {Head} from "@inertiajs/vue3";
</script>

<template>
<Head title="Blogs"/>

<AuthenticatedLayout>
Habits hether
</AuthenticatedLayout>
</template>
5 changes: 5 additions & 0 deletions resources/views/blogs.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@extends("layouts.main")

@section("content")
Blogs here
@stop
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Route::get('/experience', \App\Http\Controllers\Views\ShowExperienceController::class)->name('experience');
Route::get('/capabilities', \App\Http\Controllers\Views\ShowCapabiltiesController::class)->name('capabilities');
Route::get('/portfolio', \App\Http\Controllers\Views\ShowProjectsController::class)->name('projects');
Route::get('/blogs', \App\Http\Controllers\Views\ShowBlogsController::class)->name('blogs');

require __DIR__ . '/auth.php';
require __DIR__ . '/blog.php';

0 comments on commit a1fadb3

Please sign in to comment.