Update BookmarkController
This commit is contained in:
parent
86d7d1a928
commit
a230265d7b
1 changed files with 10 additions and 6 deletions
|
@ -16,23 +16,27 @@ class BookmarkController extends Controller
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'item' => 'required|integer|min:1'
|
'item' => 'required|integer|min:1'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$profile = Auth::user()->profile;
|
$profile = Auth::user()->profile;
|
||||||
$status = Status::findOrFail($request->input('item'));
|
$status = Status::findOrFail($request->input('item'));
|
||||||
|
|
||||||
$bookmark = Bookmark::firstOrCreate(
|
$bookmark = Bookmark::firstOrCreate(
|
||||||
['status_id' => $status->id], ['profile_id' => $profile->id]
|
['status_id' => $status->id], ['profile_id' => $profile->id]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(!$bookmark->wasRecentlyCreated) {
|
||||||
|
$bookmark->delete();
|
||||||
|
}
|
||||||
|
|
||||||
if($request->ajax()) {
|
if($request->ajax()) {
|
||||||
$response = ['code' => 200, 'msg' => 'Bookmark saved!'];
|
$response = ['code' => 200, 'msg' => 'Bookmark saved!'];
|
||||||
} else {
|
} else {
|
||||||
$response = redirect()->back();
|
$response = redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue