#help, redirected to the wrong page

5 messages · Page 1 of 1 (latest)

icy widget
#

im new to laravel, so i was following this guy tutorial https://www.youtube.com/watch?v=l6UlYfAsoR0&list=PLm8sgxwSZofdmlPxaDB7fRLv_NVe2uFKl&index=7 so i followed everything he did, but i ran into a problem where i was unable to redirect to the correct link, here is the code.
AdminController.php:
public function add_category(Request $request){
$category = new Category;

    $category->category_name = $request->category; 

    $category->save();

    return redirect()->back();
}

web.php:
Route::post('add_category', [AdminController::class,'add_category'])->
middleware(['auth', 'admin'])->name('admin.add_category')

category.blade.php:
<form action="{{url('add_category')}}" method="POST">

              @csrf
              
                <div>
                      <input type="text" name="category">
                      <input class="btn btn-primary" type="submit" value="Add Category">
                  </div>
            </form>

for some reason when i clicked the add category btn, it sends me to the home page, please tell me what is wrong with it and if you guys have a better idea to work it please let me know, much thanks

wary path
#

If a redirect back always sends you to the homepage, regardless of what page you're at, it's likely you have a referrer policy which is just sending the domain as the referrer

icy widget
#

so what should i do to solve this problem?

wary path
#

Firstly check if the referrer header is present on such a request

icy widget
#

so uhh apparently, it never went to add_category, its just straight up coming from view_category, so what should i do now?