I was having another laravel question here. I was facing 404 error when clicking the button Confirm Registration on the purpose of changing its database based on the item id on the view. Logically, I think my code should have work on this part.
<a href="{{ route('registration.confirm', $view->uniquecode) }}" >Confirm Registration</a>
However, it comes up 404 Error. Herby I include all the related code in the section.
Error
Frontend (To prove that the data passing is successful in the view)
web.php
Route::controller(ResidenceController::class)->group(function(){
Route::get('/residence/register', 'registration')->name('residence.register');
Route::get('/residence/search', 'SearchProperty')->name('residence.search');
Route::get('/registration/confirmation/{$uniquecode}', 'ConfirmRegistration')->name('registration.confirm');
});
The focus is on:
Route::get('/registration/confirmation/{$uniquecode}', 'ConfirmRegistration')->name('registration.confirm');
Controller
public function ConfirmRegistration($uniquecode){
$confirm = Properties::where('uniquecode', $uniquecode)->update(['status'=>'pending', 'tenant_id'=>Auth::user()->id]);
if($confirm){
session()->flash('alert-success','Successfully Applied');
}
else{
session()->flash('alert-warning','Error Occured');
}
}
register.blade.php
@foreach ($toSearch as $key=>$view)
<div style="width: 50rem;">
<div >
<div >
<div >
<div >
<img src="{{ (!empty($tenant->unit_image))? url('uploads/properties/'.$tenant->unit_image):url('uploads/properties/default.jpg') }}" alt="unit image" >
</div>
<div >
<table>
<tr>
<td style="width: 20%">Property</td>
<td style="width:10%; text-align: center">:</td>
<td>{{$view->name}}</td>
</tr>
<tr>
<td>Address</td>
<td style="text-align: center">:</td>
<td>{{$view->address1}},{{$view->address2}},{{$view->city}}</td>
</tr>
<tr>
<td>Landlord</td>
<td style="text-align: center">:</td>
<td>{{$view->landlord->name}}</td>
</tr>
<tr>
<td>Contact No</td>
<td style="text-align: center">:</td>
<td>{{$view->landlord->phone_number}}</td>
</tr>
<tr>
<td>Status</td>
<td style="text-align: center">:</td>
<td>{{$view->status}}</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<br>
<!--To confirm registration-->
@if( $view->status != 'approved')
<a href="{{ route('registration.confirm', $view->uniquecode) }}" >Confirm Registration</a>
@endif
</div>
@endforeach
The focus is on:
@if( $view->status != 'approved') uniquecode) }}" >Confirm Registration @endif
CodePudding user response:
you need to use post
method for inserting data (register),
anyway, change your route parameter $uniquecode
to uniquecode
.
and when you use route
second argument is a compact, use
route('registration.confirm',['uniquecode' => $view->uniquecode]);