Compare commits

..

No commits in common. "ab3611cbce65a9ffba46e598a8120fa48cfda49b" and "2161e1c2262ed9eb7b8e571f6138253953e0a78f" have entirely different histories.

13 changed files with 9 additions and 204 deletions

View File

@ -11,9 +11,9 @@ A little project because I haven't made anything new in a while, I would like to
* [x] Bookmark index * [x] Bookmark index
* [x] Bookmark pagination * [x] Bookmark pagination
* [x] Bookmark editing (title, description, url) * [x] Bookmark editing (title, description, url)
* [x] Bookmark tag editing * [ ] Bookmark tag editing
* [ ] Tag cloud * [ ] Tag cloud
* [x] Tag permalink * [ ] Tag permalink
* [ ] Multi-user support * [ ] Multi-user support
## Developing ## Developing

View File

@ -3,7 +3,6 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Bookmark; use App\Models\Bookmark;
use App\Models\Tag;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class BookmarkController extends Controller class BookmarkController extends Controller
@ -71,17 +70,6 @@ class BookmarkController extends Controller
$bookmark->href = $request->post('href'); $bookmark->href = $request->post('href');
$bookmark->save(); $bookmark->save();
$tags_input = trim($request->post('tags', ''));
$tags_input = preg_split('/\s+/', $tags_input);
$tags = [];
foreach ($tags_input as $tag_input) {
$tag = Tag::firstOrCreate(['name' => $tag_input]);
$tags[$tag->id] = true;
}
$bookmark->tags()->sync(array_keys($tags));
return redirect()->action( return redirect()->action(
[self::class, "show"], [ [self::class, "show"], [
"bookmark" => $bookmark, "bookmark" => $bookmark,

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers;
use App\Models\Tag;
use Illuminate\Http\Request;
class TagController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(Tag $tag)
{
return view('tag.show', [ 'tag' => $tag, ]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Tag $tag)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Tag $tag)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Tag $tag)
{
//
}
}

View File

@ -4,8 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
class Bookmark extends Model class Bookmark extends Model
{ {
@ -13,8 +12,8 @@ class Bookmark extends Model
protected $table = 'bookmarks'; protected $table = 'bookmarks';
public function tags(): BelongsToMany public function tags(): HasMany
{ {
return $this->belongsToMany(Tag::class); return $this->hasMany(BookmarkTag::class, 'bookmark_id');
} }
} }

View File

@ -3,10 +3,10 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\Pivot;
class BookmarkTag extends Pivot class BookmarkTag extends Model
{ {
use HasFactory; use HasFactory;

View File

@ -4,16 +4,10 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Tag extends Model class Tag extends Model
{ {
use HasFactory; use HasFactory;
protected $fillable = ['name']; protected $fillable = ['name'];
public function bookmarks(): BelongsToMany
{
return $this->belongsToMany(Bookmark::class);
}
} }

View File

@ -1,32 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table(
'bookmarks_tags', function (Blueprint $table) {
$table->unique(['bookmark_id', 'tag_id']);
}
);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table(
'bookmarks_tags', function (Blueprint $table) {
$table->dropUnique('cache_bookmark_id_tag_id_unique');
}
);
}
};

View File

@ -1,31 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create(
'bookmark_tag', function (Blueprint $table) {
$table->foreignId('bookmark_id');
$table->foreignId('tag_id');
$table->timestamps();
$table->primary(['bookmark_id', 'tag_id']);
}
);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::drop('bookmark_tag');
}
};

View File

@ -9,15 +9,6 @@
"date tags" "date tags"
"actions actions"; "actions actions";
form & {
grid-template-areas:
"title"
"description"
"href"
"tags"
"actions";
}
margin-bottom: 1em; margin-bottom: 1em;
padding: 0; padding: 0;
border: 2px solid #540B0E; border: 2px solid #540B0E;
@ -83,14 +74,9 @@
} }
&-tags { &-tags {
grid-area: tags;
font-size: 0.8em; font-size: 0.8em;
grid-area: tags;
text-align: right; text-align: right;
form & {
font-size: 0.9em;
text-align: left;
}
} }
&-tag { &-tag {
@ -102,17 +88,5 @@
border-radius: 7px; border-radius: 7px;
background-color: #9E2A2B; background-color: #9E2A2B;
color: #FFF3B0; color: #FFF3B0;
a {
&,
&:active,
&:visited {
color: #FFF3B0;
}
&:hover {
color: #000;
}
}
} }
} }

View File

@ -25,12 +25,6 @@
</label> </label>
<textarea name="description" class="form-textarea">{{ $bookmark->description }}</textarea> <textarea name="description" class="form-textarea">{{ $bookmark->description }}</textarea>
</div> </div>
<div class="bookmark-tags form-row form-row-stacked">
<label class="form-label" for="description">
Tags:
</label>
<input type="text" class="form-input" name="tags" value="@foreach ($bookmark->tags as $tag){{ $tag->name }} @endforeach">
</div>
<div class="form-row align-right bookmark-actions"> <div class="form-row align-right bookmark-actions">
<a class="form-button" href="{{ action('BookmarkController@show', ['bookmark' => $bookmark]) }}">Cancel</a> <a class="form-button" href="{{ action('BookmarkController@show', ['bookmark' => $bookmark]) }}">Cancel</a>
<input type="submit" class="form-button" value="Save"> <input type="submit" class="form-button" value="Save">

View File

@ -18,7 +18,7 @@
<ul class="bookmark-tags"> <ul class="bookmark-tags">
@foreach ($bookmark->tags as $tag) @foreach ($bookmark->tags as $tag)
<li class="bookmark-tag"> <li class="bookmark-tag">
<a href="{{ action('TagController@show', $tag) }}">{{ $tag->name }}</a> {{ $tag->tag->name }}
</li> </li>
@endforeach @endforeach
</ul> </ul>

View File

@ -1,9 +0,0 @@
@extends('layouts.app')
@section('content')
<div>
@foreach ($tag->bookmarks as $bookmark)
<x-bookmark :bookmark="$bookmark" />
@endforeach
</div>
@endsection

View File

@ -1,7 +1,6 @@
<?php <?php
use App\Http\Controllers\BookmarkController; use App\Http\Controllers\BookmarkController;
use App\Http\Controllers\TagController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::get( Route::get(
@ -12,9 +11,3 @@ Route::get(
Route::resource('bookmarks', BookmarkController::class); Route::resource('bookmarks', BookmarkController::class);
Route::post('/bookmarks/{bookmark}', [BookmarkController::class, 'update']); Route::post('/bookmarks/{bookmark}', [BookmarkController::class, 'update']);
Route::resource('tags', TagController::class)->parameters(
[
'tags' => 'tag:name', // tag names in url, rather than ids
]
);