Laravel trouble routing to update Controller - laravel

I'm trying to edit a Alumne model with a model Form but I only have a NotFoundHttpException
The application only fails when I confirm the edit form. I think the problem is in the Form::model line but don't know.
Here's the entire code:
http://laravel.io/bin/62eq
Thanks.

All looks correct...
Check if $alumne really has id or is named different like alumne_id or id_alumne... Is the only thing may be.

Related

How to return to another page after finishing process in Laravel?

This is a little bit hard to understand even the title I put. Sorry about that I just do not know how to clearly explain this, but I will try...
So for example I have a controller and inside that controller I have a function which return the data in the table of my database. then in the last column of every row, I make view,add,edit,delete options as links. When a user clicks on the add for example, they will redirect to an add page. After they submit the form of the add page. they should be redirected to the first page that return the data from the table. but the problem is, the variables of foreach loop in the first page do not got recognized by laravel anymore. because they do not got processed since the route does not goes to the controller and to the function that return the data instead it goes to add function.
So I want to know is there anyway to solve this? If you could provide sample code, I would appreciate a lot thanks
From your explanation, I believe the code to go back to the original page after adding, editing etc is simply return redirect()->back(). This will take the user back to the previous page. As for data continuity, one approach would be considering using sessions. They save data globally and can be accessed from any controller once saved. To do this, simply save the data with session(['session_name' => $data]) and to retrieve the data use session('session_name'). Let me know if this helps!
If you want ti redirect after something like a login or an activation process you can do it with something like this:
return redirect()->to('login')
You can specify the path from your web.php file as you can see in my example in 'myPath'
As #DerickMasai correctly pointed out it is better to use named routes instead of hard coding the path itself.
Naming a route can work like so:
Route::get('/login', [LoginController::class, 'index'])->name('login');

LARAVEL - INPUT ERROR - The POST method is not supported for this route. Supported methods: GET, HEAD

I'm trying to create an input form but couldn't find the solution from the error
This is what it said
My View Code
My Controller
My Router
I've tried some tips online but it still won't work
It's because your route name is not defined. you should add the route name like this
Route::post('CreateItem', 'CreateItem#insert')->name('CreateItem');
I think is related to the route name. Have you check which uri is posting the form? Can you try:
Route::post('/createItem', function () {
//
})->name('createItem');
Sorry, got the answer
Route::post('CreateItem','CreateItem#insert');
to
Route::post('/create_item','CreateItem#insert');
and
class CreateItem extends Controller
in my question, I typed the wrong controller name, it should be CreateItem
Thanks for the effort to answer my question tho..

Getting the URL details - Laravel

I am working on a Laravel project, where I want to toggle partials based on the URL data like
foo.bar.com/#itemone/create
foo.bar.com/#itemone/view
Basically, I want to pass whether it is create or view to the partials like this
#include('partials.layouts._core_activity_header',['layout_type' => "create"])
How do I achieve this? Any help would be appreciated.
you can use the route name
Route::getCurrentRoute()->getName()
this will return the route alias

Is there any way to make the template get updated when the model is updated?

I am using FreeMarker to generate an HTML.
However, I would like the template to get updated if I update the model.
Is it possible to achieve this kind of request ?
It just doesn't make sense to call to template.process(..) every time the model changes.
Thanks !
Well I guess it's not possible to have the html changed whenever the model is updated. Thanks ! :)

how can i add #somelink to laravel route

I want to create a laravel route that links to a named anchor in a page. Could someone help with how to achieve that. Example: return Redirect::route('admin.articles.edit#somelink', $article->id);
In this case the route is in a controller which is redirecting back to the pages' comments section
I was looking for this and stumbled upon this older question.
The "possible duplicate" has an answer for the case where the link is created in a view (i.e. in html). It may not be immediately clear that this can also be used in returning a redirect route from a controller, as OP seemed to require (some years ago :).
At least in Laravel 5.5, it is possible to use this in the redirect()->to() function, e.g.:
return redirect()->to(
route('admin.articles.edit', [$article->id]) . "#somelink"
);
Based on this answer.

Resources