-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'blog-mvp' of https://github.com/SethSharp/Portfolio int…
…o blog-mvp
- Loading branch information
Showing
17 changed files
with
255 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
database/migrations/2024_01_24_014509_create_blogs_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
database/migrations/2024_01_24_014627_create_tags_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
database/migrations/2024_01_24_014650_create_blog_tag_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@extends("layouts.main") | ||
|
||
@section("content") | ||
Blogs here | ||
@stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters