I have testimonials
table where I get reviews from users, for backend(admins) everything works perfectly, my issue is with front-end form where users (logged or guests) can send their testimonials, somehow it doesn't works and also not shows any error to see which part has issue.
Here are my codes:
Routes
Route::get('/write-testimonials', 'frontend\FrontendController@testimonialcreate')->name('write-testimonials');
Route::post('/write-testimonials', 'frontend\FrontendController@testimonialcreate')->name('write-testimonialsstore');
Controller:
public function testimonialcreate()
{
return view('front.testimonials-create');
}
public function testimonialcreatestore(Request $request)
{
$this->validate($request, array(
'body'=>'required',
'user_email' => 'nullable',
'user_name' => 'nullable',
'image' => 'nullable|image',
'status_id' => 'required|numeric',
'user_id' => 'nullable|numeric',
));
$testimonial = new Testimonial;
$testimonial->body = $request->input('body');
$testimonial->user_email = $request->input('user_email');
$testimonial->user_name = $request->input('user_name');
$testimonial->status_id = $request->input('status_id');
$testimonial->user_id = $request->input('user_id');
if ($request->hasFile('image')) {
$image = $request->file('image');
$filename = 'Testimonial' . '-' . time() . '.' . $image->getClientOriginalExtension();
$location = public_path('images/');
$request->file('image')->move($location, $filename);
$testimonial->image = $filename;
}
$testimonial->save();
return redirect()->back()
->with('success', 'Testimonial sent!');
}
And my blade
<form action="{{route('write-testimonialsstore')}}" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="col-md-8">
@guest
<div class="row">
<div class="col-md-4">
{{Form::label('user_email', 'Email')}}
{{Form::text('user_email', null, array('class' => 'form-control'))}}
</div>
<div class="col-md-4">
{{Form::label('user_name', 'Name')}}
{{Form::text('user_name', null, array('class' => 'form-control'))}}
</div>
<div class="col-md-4">
{{Form::label('image', 'Image')}}
{{Form::file('image', array('class' => 'form-control'))}}
</div>
</div>
@endguest
<div class="row">
<div class="col-md-12">
<div class="mt-20">
{{Form::label('body', 'Write your testimonial')}}
{{Form::textarea('body', null, array('class' => 'form-control'))}}
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="row">
<label for="status_id" hidden>Status</label>
<input type="hidden" name=status_id" value="1">
@auth
<label for="user_id" hidden>User</label>
<input type="hidden" name="user_id" value="{{ Auth::user()->id }}" placeholder="{{ Auth::user()->username }}">
@endauth
</div>
</div>
<div class="mt-20">
{{ Form::submit('Send', array('class' => 'btn btn-success')) }}
</div>
</form>
any idea?
Looks like you misunderstood the route names.
Route::post('/write-testimonials', 'frontend\FrontendController@testimonialcreate')->name('write-testimonialsstore');
The name after @
sign is action name. Post request have to use another action name. So just change it from @testimonialcreate
to @testimonialcreatestore
for the Route::post
line/