I can't get the PaperID to store into my Bookmarks DB
here is my controller for the bookmark store function
public function store(Request $request)
{
$request->validate([
'BookmarkName' => 'required',
]);
$paper = DB::table('papers')
->where('PaperID', '=', $request->paper_id)
->value('PaperID');
$bm = new Bookmarks();
$bm->BookmarkName=$request->BookmarkName;
$bm->paper_id = $paper;
$bm->save();
return redirect()->back()->with('success','Bookmark Added');
}
here is the form to call the function
<form class="bookmarkInput" action="{{ route('Bookmarks')}} " method="POST" >
@csrf
<div class="group">
<input class="inputInfo" type="text" name="BookmarkName" required>
<span class="highlight"></span>
<span class="bar"></span>
<label class="infoLabel">Bookmark Name</label>
</div>
<br>
<br>
<button class="redBtn" type="submit">Add</button>
</form>
here is the route for it
Route::post('/Bookmarked', [App\Http\Controllers\BookmarkController::class, 'store'])->name('Bookmarks');
I do not know why it isn't getting the ID calling papers DB seems good but it doesn't want to get the current ID of the paper I want to bookmark
My Answer:
It looks like you are trying to retrieve the PaperID from the papers table based on the paper_id that is being passed in the request. However, it seems like the issue might be with how you are passing the paper_id in the request.
In your form, you need to include a hidden input field to pass the paper_id along with the BookmarkName. You can do this by adding the following line inside your form:
html
Make sure that you are passing the $paper variable to your view where the form is being displayed.
Once you have added the hidden input field, the paper_id should be available in the request in your controller's store function. You can then use this paper_id to retrieve the PaperID from the papers table.
If you are still facing issues, you can try debugging by dumping the $request->paper_id to see if the paper_id is being passed correctly in the request.
php
dd($request->paper_id);
This will help you determine if the issue lies in how the paper_id is being passed in the request.
Rate this post
4 of 5 based on 5436 votesComments