Reputation: 65
I want to submit the form to usercontroller file and call function invitebyemail.
When I click on submit it gives me error like "Whoops, looks like something went wrong."
Below are the structure of my Files and code.
Route File:
Route::POST('event/inviteforevent', 'UserController@invitebyemail');
Blade.php file
<form action="{{ route('inviteforevent') }}" method="POST">
<input type="email" class="form-control full-width" id="add-members-event-email" name="email" placeholder="Email address">
<input type="hidden" class="form-control full-width" name="eventid" value="{{ $event->id }}" >
<input type="submit" name="invite" value="submit" />
</form>
UserController File:
public function invitebyemail(Request $request){
$event = Event::find($request->eventid);
$timelineId = $event->timeline_id;
$username = Auth::user()->username;
$timelines = Timeline::find($timelineId);
return redirect()->back()->with('message', 'Invitation send to user by email.');
}
Upvotes: 0
Views: 77
Reputation: 336
You have to add {{ csrf_field() }}
which was suggested but one question? Where is your table names and id in your form opening? How that form have to know which table you want to add data in?
You have to add $events
and $events->id
into your form
Upvotes: 0
Reputation: 11936
The route()
helper function expects a route name.
Route::post('event/inviteforevent', 'UserController@invitebyemail')->name('inviteforevent');
Edit
Run php artisan serve
and access your server at http://localhost:8000
. You have not set the web root and laravel url rewrite won't work properly along with the url
and route
methods generating wrong links.
Upvotes: 1
Reputation: 645
Apart from the Route change that was suggested, you may need to add the
{{ csrf_field() }}
after
<form action="{{ route('inviteforevent') }}" method="POST">
Read more here: https://laravel.com/docs/5.4/csrf#csrf-introduction
Upvotes: 1
Reputation: 1158
Please replace this code in route:-
Route::post('event/inviteforevent', 'UserController@invitebyemail')->name('inviteforevent');
OR
Route::post('event/inviteforevent', ['as' => 'inviteforevent', uses' => 'UserController@invitebyemail']);
Upvotes: 0
Reputation: 2523
change
Route::POST('event/inviteforevent', 'UserController@invitebyemail');
to
Route::POST('event/inviteforevent', 'UserController@invitebyemail')->name("inviteforevent");
Reference : https://laravel.com/docs/5.4/routing#named-routes
Upvotes: 0