mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-26 00:03:16 +00:00
Add Bookmark feature
This commit is contained in:
parent
b7b916e211
commit
1c63184133
6 changed files with 99 additions and 1 deletions
10
app/Bookmark.php
Normal file
10
app/Bookmark.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Bookmark extends Model
|
||||
{
|
||||
protected $fillable = ['profile_id', 'status_id'];
|
||||
}
|
38
app/Http/Controllers/BookmarkController.php
Normal file
38
app/Http/Controllers/BookmarkController.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use App\{Bookmark, Profile, Status};
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BookmarkController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'item' => 'required|integer|min:1'
|
||||
]);
|
||||
|
||||
$profile = Auth::user()->profile;
|
||||
$status = Status::findOrFail($request->input('item'));
|
||||
|
||||
$bookmark = Bookmark::firstOrCreate(
|
||||
['status_id' => $status->id], ['profile_id' => $profile->id]
|
||||
);
|
||||
|
||||
if($request->ajax()) {
|
||||
$response = ['code' => 200, 'msg' => 'Bookmark saved!'];
|
||||
} else {
|
||||
$response = redirect()->back();
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
|
@ -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->bigInteger('status_id')->unsigned();
|
||||
$table->bigInteger('profile_id')->unsigned();
|
||||
$table->unique(['status_id', 'profile_id']);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('bookmarks');
|
||||
}
|
||||
}
|
9
resources/assets/js/components/bookmarkform.js
vendored
Normal file
9
resources/assets/js/components/bookmarkform.js
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
$(document).ready(function() {
|
||||
|
||||
$('.bookmark-form').submit(function(e) {
|
||||
e.preventDefault();
|
||||
var el = $(this);
|
||||
var id = el.data('id');
|
||||
var res = axios.post('/i/bookmark', {item: id});
|
||||
});
|
||||
});
|
|
@ -2,4 +2,7 @@
|
|||
|
||||
return [
|
||||
'emptyTimeline' => 'This user has no posts yet!',
|
||||
'emptyFollowers' => 'This user has no followers yet!',
|
||||
'emptyFollowing' => 'This user is not following anyone yet!',
|
||||
'savedWarning' => 'Only you can see what you\'ve saved',
|
||||
];
|
|
@ -29,7 +29,11 @@
|
|||
</form>
|
||||
<span class="icon-speech"></span>
|
||||
<span class="float-right">
|
||||
<span class="icon-notebook"></span>
|
||||
<form class="bookmark-form" method="post" action="/i/bookmark" style="display: inline;" data-id="{{$item->id}}" data-action="bookmark">
|
||||
@csrf
|
||||
<input type="hidden" name="item" value="{{$item->id}}">
|
||||
<button class="btn btn-link text-dark p-0" type="submit"><span class="icon-notebook" style="font-size:25px;"></span></button>
|
||||
</form>
|
||||
</span>
|
||||
</div>
|
||||
<div class="likes font-weight-bold">
|
||||
|
|
Loading…
Reference in a new issue