When a user click 'Delete' button, following URI is generated
http://localhost:8888/item?id=32
in my route.php I used
Route::get('item/id={ID}','ItemsController#destroy');
But it doesn't get the input and delete the record. I have created my destroy method properly and when I give URI manually as
http://localhost:8888/item/id=32
it deletes the record.
Why Laravel doesn't capture item?id=32? How to fix this?
Thanks in advance.
You have to change the route to make this("http://localhost:8888/item?id=32") working, you can try the following:
Route::get('item','ItemsController#destroy');
and receive the id in the controller, by doing following things:
$id = Input::get('id');
// then do whatever you want for this id.. here Destroy
Second way
If you want to make "http://localhost:8888/item/id=32" working, then you have to change the delete link. Make the link like the below one:
'http://localhost:8888/item/id=' + {IdWillBePlacedHere}
Related
in laravel 8 i will redirect the user to a route after doing the query.
There are many tabs on the page where I want the user to be transferred
I wrote the code like this
(Of course I know it's wrong, but I wanted to try, and yet I did not think of another way
return redirect()->route('admin.auth.user.show', $user . "#edit-information")->withFlashSuccess(__('The user was successfully updated.'));
I get an error with this code
What is your solution?
What you can do to activate for example bootstrap tab based on #web paramater is use the redirect() method like this:
return redirect()->route('backend.settings.show', ['eshop' => $eshop->id, '#homeImages']);
Eshop is regular route parameter but '#homeImages' is added to the end of the route which is then picked up by the js on page load.
In Laravel there is a withFragment method, which add a fragment identifier to the URL.
return redirect()->route('admin.auth.user.show', ['user' => $user])->withFragment('edit-information');
https://laravel.com/api/8.x/Illuminate/Http/RedirectResponse.html#method_withFragment
My controller posts a form to create a new page. After posting the form I need to redirect the user to the new page that will have the contents for that page that were entered in the previous form. If I simply do return view('mynewpageview', compact('mycontent')); where my mycontent is the object used to execute the $mycontent->save(); command, I carry the risk for someone refreshing the url thus posting the same content twice by creating a new page.
Instead I would like to redirect the user to the actual page url.
My route is
Route::get('/newpage/{id}', 'PageController#pagebyid'); and if I use return redirect()->route('/newpage/$pageid'); where $pageid = $mycontent->id; I get Route not defined error.
What would be the solution either to stop someone from resubmitting the content or a correct syntax for passing the parameter?
The correct answer that works for me is -
Give your route a name in the routes file
Then pass the parameters with an array as shown below in the controller.
return redirect()->route('newpageid', ['id' => $pageid]);
With basic (unnamed) routes, the correct syntax was return redirect('/newpage/'.$pageid);
You have already found out you can alternatively use named routes.
Last but not least, thanks for having considered the "double submit" issue! You have actually implemented the PRG pattern :)
i have some problem about routes in laravel
Route::get('aset/create', 'TransaksiController#aset_create');
Route::get('aset/{id}', 'TransaksiController#aset_view');
these routes was fine, but when i switch the position like
Route::get('aset/{id}', 'TransaksiController#aset_view');
Route::get('aset/create', 'TransaksiController#aset_create');
the aset/create was went to aset/view
whats happening?
thanks!
The aset/create will trigger the Route::get('aset/{id}', 'TransaksiController#aset_view'); as you can see the template displayed is for view aset-view.blade.php not the template for the create, so laravel identifies create as the id param so your db query will return no rows creating the error you see,
To fix this problem you either keep the original order or you change the view route to match only number(or not match create)
Route::get('aset/{id}', 'TransaksiController#aset_view')->where('id', '[0-9]+');
aset-view.blade.php file, that's where you have issue. You are either accessing a variable as object, it could be something null or array which you are accessing as an object
{id} is a parameter for passing it is receving now create as parameter.since it is in top.Rearrange will solve the problem.id will catch anything you pass
I need someway to redirect my app to a previous url.
The problem comes when i make a submit that goes wrong, the redirect->back previous url is someway "overwrited" and i cannot get the previous real url anymore, instead the app makes the submit again.
The only thing that i tried is the redirect back, because i can't find another way to do it :S
So i´m wondering if there is a way to achieve that, redirect the app to a previous url without considering the submit fails and all this stuff.
Thank you.
Yo can try with:
return Redirect::to(URL::previous());
You can store URLs in session and then make Laravel redirect 2 or 3 pages back. Simple example of code to store URL in session:
$links = session->has('links') ? session('links') : []; // Get data from session
array_unshift($links, $_SERVER['REQUEST_URI']); // Add current URI to an array
session(compact('links')); // Save an array to session
And example of code for redirecting:
return redirect(session('links')[2]);
I want to show all users page wise initially. So if I browse http://mydomain/user it will redirect to http://mydomain/user/page/1 and so on. But if I browse http://mydomain/user/1 it will show only single user with id of user.
http://mydomain/user/1 >> it works fine. But as I want pagination so I want to redirect http://mydomain/user to http://mydomain/user/page/1 always
My Routing Info is:
$route['user/(:num)'] = 'user/index/$1';
$route['user'] = 'user/page/$1';
But when I pressed to http://mydomain/user it does not rout to user/page/$1. I have index() method which output to single user information if I give slug. so get a page wise list I used routing and page method. But it is not working. it gives 404 Page not found
Could anybody have solution please..
I think you need to look at the manual for routing:
http://ellislab.com/codeigniter/user-guide/general/routing.html
As far as i can see your second route doesn´t make much sense, you are calling the method page() of your User class - and trying to pass in $1 which does not exist. I think you need to explain better what you want to achieve with your second route - I don´t really see why you need it at all at the moment.