I am beginner in `Laravel`. I am creating a admin panel in Laravel. I am getting data from database by id (Edit Page). And In my edit page, my form is not submitting correct. I mean form's `action` attribute didn't set fine. Wait, here is my code:
`View.blade.php`
<div class="card chapterCard">
<div class="card-body">
@foreach($data as $chapter)
// See this in action
<form method="POST" action="{{ action('ChaptersController@store') }}">
@csrf
<h2 class="h2-responsive text-center">Edit Chapter</h2>
<div class="form-group row">
<div class="col-md-12">
<div class="md-form">
<label for="chapterName">Chapter Name</label>
<input type="text" name="chapterName" id="chapterName" class="form-control" value="{{ $chapter->chapter }}">
</div>
</div>
<div class="col-md-12">
<div>
<button type="submit" class="btn btn-primary btn-block">Save</button>
</div>
</div>
</div>
</form>
@endforeach
</div>
</div>
Route
Route::prefix('/admin')->group(function () {
Route::get('/chapters/sahih_bukhari/edit/{chapter_number}', 'ChaptersController@editSahihBukhari')->name('edit_chapter_sahih_bukhari');
});
// For edit Form
Route::post('store', 'ChaptersController@store');
ChaprtersController.php
class ChaptersController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct() {
$this->middleware('auth');
}
public function editSahihBukhari($chapter_number) {
$chapter = Chapters::where([
['chapter_number', $chapter_number],
['source', 'Sahih Bukhari']
])->get();
return view('edit_chapter_sahih_bukhari', ['data' => $chapter]);
}
// For Edit Form
public function store(Request $request) {
print_r($request->input());
}
}
When i click on submit, to check if it is working, It redirects me to http://localhost:8000/store
. It means it goes to another page. But I want it not to o to another page after submitting, It should stay on the same page. I don't know what i am doing wrong. I googled a lot, I found a lot of answers but all of them were doing this that "After submitting, it goes to another page" But I want it to stay on the same page. Please help me, how can it be done. I am stuck