Ramzan Mahmood
Ramzan Mahmood

Reputation: 1901

laravel route redirect issue (laravel 5.3)

I am using a route with any type and then in this method I am treting on the base of a type of request.

route

Route::any('/setting/custom-header/{id?}', 'SettingController@customHeader');

From the controller before checking the type I check it like this

if ($id == Auth::user()->id || Auth::user()->is_admin){}

As where the request is get it gives a view and my url is this http://app-full.dev/setting/custom-header/1

Here 1 is the id of the user through which I am logged in. I am returning the view as following:

return view('setting/custom-header')->with(compact('custom_headers','id'));

It's fine for me.

When request is post it comes in method. After creating data i want return back as above url mean same on http://app-full.dev/setting/custom-header/1 mean id at the end through which user logged in here i am using redirect as

return redirect('setting/custom-header/id');

here /id is actually the id of user .. which I don't know how can I give the id here so that url can come in the proper way instead of keyword id at the end. Thanks if anyone can help to resolve this issue!

Upvotes: 1

Views: 516

Answers (2)

Bart Bergmans
Bart Bergmans

Reputation: 4121

The following code will retreive the user ID and put it in the URL.

return redirect('setting/custom-header/' . Auth::id()); 

To pass it to a view:

return view('setting/custom-header')->with(['userid' => Auth::id()]);

and then use it:

window.location.href = "/setting/custom-header/{{ $userid }}";

Upvotes: 1

Rohit shah
Rohit shah

Reputation: 819

Make Your Route As Follows

Route::post('/setting/custom-header/{id?}',['as'=>'giveSomeName','uses'=>'SettingController@customHeader']);

And While Redirect use this name,

return redirect()->route('giveSomeName',[$id]);

Hope This Works For you

Upvotes: 0

Related Questions