You need to show us your Blade template, relevant route(s) and Controller.
Post to controller from a form action
Hello to all, I'm trying to post an action from a form directly to the controller (It's an update action). I use laravel 5.5 so the collective don't work (or I haven't made it work) so I use pure HTML. I found this
<form role="form" method="post" action="{{action('Addressee_Controller@store')}}">
but it doesn't seem to work. Any ideas??
--view
@extends('layouts.layout')
@section('content')
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-sm-6">
<h3 class="m-t-none m-b">Addressee</h3>
<form role="form" method="post" action="{{action('Addressee_Controller@store')}}">
<div class="form-group">
<label>Name <span class="required">*</span></label>
<input type="text" class="form-control" name="ADR_NAME" @if($adrs_dtls)value="{{ old('', $adrs_dtls->ADR_NAME) }}"@endif placeholder="Name" required/>
</div>
<div class="form-group">
<label>Abbreviation <span class="required">*</span></label>
<input type="text" class="form-control" name="ADR_ABRV" @if($adrs_dtls)value="{{ old('', $adrs_dtls->ADR_ABRV) }}"@endif placeholder="Name" required/>
</div>
</form>
</div>
</div>
</div>
@endsection
--controller
public function store(Request $request)
{
//return view('addressee_dtls')->with('adrs_dtls', $adrs);
print_r($request);
}
--route
Route::get('/', function () {
return view('welcome');
});
Route::get('AddresseeList/{srchtext?}','Addressee_Controller@AdrsList');
Route::get('/addressee/{id}', 'Addressee_Controller@show');
Route::get('/addressee', 'Addressee_Controller@create');
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
You have no route defined for that action:
Route::post('AddresseeList', 'Addressee_Controller@store');
When I do that, I get redirected to AddresseeList (as I want to) but then I don't get print_r the object in the controller and I get a message that the page is expired.
Your form is also missing
{{csrf_field()}}
Thank you all!!! That was it. I missed the route and the
{{csrf_field()}}
I really can't vote for the answer because it was a combination of the two.
this case is similar with me.
view
@php
if ($user == null) {
$action = "MemberController@add";
}
else {
$action = "MemberController@store";
}
@endphp
<form action="{{ action($action) }}" method="post" class="form-horizontal">
@include('layouts.partials._alerts')
{{ csrf_field() }}
controller
public function store(Request $request)
{
dd($request);
return back()->with('success', 'Profile updated.');
}
public function add(Request $request)
{
dd($request);
return back()->with('success', 'Profile added.');
}
route
Route::post('/member/{id?}', 'MemberController@store')->name('store')->middleware('auth');
Route::post('/member/', 'MemberController@add')->middleware('auth');
form action link in generated view source
http://localhost:8000/member
my question, how to direct the request to correct controller. in this situation i want directing to add controller? fyi, condition $user = null.
Please or to participate in this conversation.