Basic bookmarks functionality
This commit is contained in:
parent
b840d164ed
commit
13e6ff1d0f
10 changed files with 173 additions and 0 deletions
23
app/Bookmark.php
Normal file
23
app/Bookmark.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Bookmark extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = ['url', 'name', 'content'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The tags that belong to the bookmark.
|
||||||
|
*/
|
||||||
|
public function tags()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany('App\Tag');
|
||||||
|
}
|
||||||
|
}
|
15
app/Http/Controllers/BookmarksController.php
Normal file
15
app/Http/Controllers/BookmarksController.php
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Bookmark;
|
||||||
|
|
||||||
|
class BookmarksController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$bookmarks = Bookmark::paginate(10);
|
||||||
|
|
||||||
|
return view('bookmarks.index', compact('bookmarks'));
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,14 @@ class Tag extends Model
|
||||||
return $this->belongsToMany('App\Note');
|
return $this->belongsToMany('App\Note');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The bookmarks that belong to the tag.
|
||||||
|
*/
|
||||||
|
public function bookmarks()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany('App\Bookmark');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes excluded from the model's JSON form.
|
* The attributes excluded from the model's JSON form.
|
||||||
*
|
*
|
||||||
|
|
11
database/factories/BookmarkFactory.php
Normal file
11
database/factories/BookmarkFactory.php
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Faker\Generator as Faker;
|
||||||
|
|
||||||
|
$factory->define(App\Bookmark::class, function (Faker $faker) {
|
||||||
|
return [
|
||||||
|
'url' => $faker->url,
|
||||||
|
'name' => $faker->sentence,
|
||||||
|
'content' => $faker->text,
|
||||||
|
];
|
||||||
|
});
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreateBookmarksTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('bookmarks', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->string('url');
|
||||||
|
$table->string('name')->nullable();
|
||||||
|
$table->text('content')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('bookmarks');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreateBookmarkTagPivotTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('bookmark_tag', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->unsignedInteger('bookmark_id');
|
||||||
|
$table->unsignedInteger('tag_id');
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->foreign('bookmark_id')->references('id')->on('bookmarks');
|
||||||
|
$table->foreign('tag_id')->references('id')->on('tags');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('bookmark_tag');
|
||||||
|
}
|
||||||
|
}
|
16
database/seeds/BookmarksTableSeeder.php
Normal file
16
database/seeds/BookmarksTableSeeder.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class BookmarksTableSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
factory(App\Bookmark::class, 10)->create();
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,5 +19,6 @@ class DatabaseSeeder extends Seeder
|
||||||
$this->call(WebMentionsTableSeeder::class);
|
$this->call(WebMentionsTableSeeder::class);
|
||||||
$this->call(IndieWebUserTableSeeder::class);
|
$this->call(IndieWebUserTableSeeder::class);
|
||||||
$this->call(LikesTableSeeder::class);
|
$this->call(LikesTableSeeder::class);
|
||||||
|
$this->call(BookmarksTableSeeder::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
23
resources/views/bookmarks/index.blade.php
Normal file
23
resources/views/bookmarks/index.blade.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
@extends('master')
|
||||||
|
|
||||||
|
@section('title')
|
||||||
|
Bookmarks «
|
||||||
|
@stop
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="h-feed">
|
||||||
|
@foreach($bookmarks as $bookmark)
|
||||||
|
<div class="h-entry">
|
||||||
|
<a class="u-bookmark-of<?php if ($bookmark->name !== null) { echo ' h-cite'; } ?>" href="{{ $bookmark->url }}">
|
||||||
|
@isset($bookmark->name)
|
||||||
|
{{ $bookmark->name }}
|
||||||
|
@endisset
|
||||||
|
|
||||||
|
@empty($bookmark->name)
|
||||||
|
{{ $bookmark->url }}
|
||||||
|
@endempty
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
@stop
|
|
@ -114,6 +114,12 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
Route::get('/{like}', 'LikesController@show');
|
Route::get('/{like}', 'LikesController@show');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Bookmarks
|
||||||
|
Route::group(['prefix' => 'bookmarks'], function () {
|
||||||
|
Route::get('/', 'BookmarksController@index');
|
||||||
|
Route::get('/{bookmark}', 'BookmarksController@show');
|
||||||
|
});
|
||||||
|
|
||||||
// Micropub Client
|
// Micropub Client
|
||||||
Route::group(['prefix' => 'micropub'], function () {
|
Route::group(['prefix' => 'micropub'], function () {
|
||||||
Route::get('/create', 'MicropubClientController@create')->name('micropub-client');
|
Route::get('/create', 'MicropubClientController@create')->name('micropub-client');
|
||||||
|
|
Loading…
Add table
Reference in a new issue