1
0
Fork 0
pixelfed/app/Http/Controllers/BookmarkController.php

43 lines
911 B
PHP
Raw Normal View History

2018-05-31 21:56:46 +00:00
<?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, [
2018-08-05 19:18:33 +00:00
'item' => 'required|integer|min:1'
2018-05-31 21:56:46 +00:00
]);
$profile = Auth::user()->profile;
$status = Status::findOrFail($request->input('item'));
$bookmark = Bookmark::firstOrCreate(
2018-08-05 19:18:33 +00:00
['status_id' => $status->id], ['profile_id' => $profile->id]
2018-05-31 21:56:46 +00:00
);
2018-08-05 19:18:33 +00:00
if(!$bookmark->wasRecentlyCreated) {
$bookmark->delete();
}
2018-05-31 21:56:46 +00:00
if($request->ajax()) {
$response = ['code' => 200, 'msg' => 'Bookmark saved!'];
2018-08-05 19:18:33 +00:00
} else {
2018-05-31 21:56:46 +00:00
$response = redirect()->back();
2018-08-05 19:18:33 +00:00
}
2018-05-31 21:56:46 +00:00
2018-08-05 19:18:33 +00:00
return $response;
}
2018-05-31 21:56:46 +00:00
}