From 1c631841334ea77bc83e585795dffe711c6e4217 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 31 May 2018 15:56:46 -0600 Subject: [PATCH] Add Bookmark feature --- app/Bookmark.php | 10 +++++ app/Http/Controllers/BookmarkController.php | 38 +++++++++++++++++++ ...18_05_31_043327_create_bookmarks_table.php | 34 +++++++++++++++++ .../assets/js/components/bookmarkform.js | 9 +++++ resources/lang/en/profile.php | 3 ++ resources/views/status/template.blade.php | 6 ++- 6 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 app/Bookmark.php create mode 100644 app/Http/Controllers/BookmarkController.php create mode 100644 database/migrations/2018_05_31_043327_create_bookmarks_table.php create mode 100644 resources/assets/js/components/bookmarkform.js diff --git a/app/Bookmark.php b/app/Bookmark.php new file mode 100644 index 000000000..65cdfec19 --- /dev/null +++ b/app/Bookmark.php @@ -0,0 +1,10 @@ +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; + } + +} diff --git a/database/migrations/2018_05_31_043327_create_bookmarks_table.php b/database/migrations/2018_05_31_043327_create_bookmarks_table.php new file mode 100644 index 000000000..e34622e36 --- /dev/null +++ b/database/migrations/2018_05_31_043327_create_bookmarks_table.php @@ -0,0 +1,34 @@ +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'); + } +} diff --git a/resources/assets/js/components/bookmarkform.js b/resources/assets/js/components/bookmarkform.js new file mode 100644 index 000000000..dd67747ae --- /dev/null +++ b/resources/assets/js/components/bookmarkform.js @@ -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}); + }); +}); \ No newline at end of file diff --git a/resources/lang/en/profile.php b/resources/lang/en/profile.php index 6d70d56a3..50b6f2429 100644 --- a/resources/lang/en/profile.php +++ b/resources/lang/en/profile.php @@ -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', ]; \ No newline at end of file diff --git a/resources/views/status/template.blade.php b/resources/views/status/template.blade.php index 401692c8c..b0019e989 100644 --- a/resources/views/status/template.blade.php +++ b/resources/views/status/template.blade.php @@ -29,7 +29,11 @@ - +
+ @csrf + + +