Daniel Supernault пре 7 година
родитељ
комит
1c63184133

+ 10 - 0
app/Bookmark.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Bookmark extends Model
+{
+    protected $fillable = ['profile_id', 'status_id'];
+}

+ 38 - 0
app/Http/Controllers/BookmarkController.php

@@ -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;
+    }
+
+}

+ 34 - 0
database/migrations/2018_05_31_043327_create_bookmarks_table.php

@@ -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 - 0
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});
+  });
+});

+ 3 - 0
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',
 ];

+ 5 - 1
resources/views/status/template.blade.php

@@ -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">