I have this route
Route::name('recruitment.edit.profile')->get('/edit-profile/{id}', 'EmployeeController#showEditProfileForm');
having a parameter id and
this code in my blade.php
<a href="{{ route('recruitment.edit.profile', $users->id) }}" class="btn btn-success">
<i class="fa fa-edit m-right-xs"></i> Edit Profile
</a>
But when I clicked the given link I got this url http://mpci-vo.dev/recruitment/edit-profile?9 and a message Whoops, looks like something went wrong.
My question why is there a ? before 9
Change route('recruitment.edit.profile', $users->id)
to
route('recruitment.edit.profile', ['id' => $users->id])
https://laravel.com/docs/5.4/helpers#method-route
Related
Please what am I doing wrong, Paymentdetails refuse to delete instead, its loading server error.There's something wrong with my code.
This is my controller
public function destroy(Paymentdetail $paymentdetail)
{
// dd($id);
if(Auth::user()->role_id == '1'){
$this->paymentdetails->delete($paymentdetail->id);
event(new Deleted($paymentdetail));
return redirect()->route('paymentdetails.index')
->withSuccess(__('Payment details deleted successfully.'));
}
else{
return redirect()->back()
->withErrors(__('Sorry! You Are Not Authorized To Delete Payment Details.'));
}
}
index.blade
<a href="{{ route('paymentdetails.edit', $paymentdetail) }}"
class="btn btn-icon edit"
title="#lang('Edit Paymentdetail')"
data-toggle="tooltip" data-placement="top">
<i class="fas fa-edit"></i>
</a>
<a href="{{ route('paymentdetails.destroy', $paymentdetail) }}"
class="btn btn-icon"
title="#lang('Delete Paymentdetail')"
data-toggle="tooltip"
data-placement="top"
data-method="DELETE"
data-confirm-title="#lang('Please Confirm')"
data-confirm-text="#lang('Are you sure that you want to delete this payment details?')"
data-confirm-delete="#lang('Yes, delete details!')">
<i class="fas fa-trash"></i>
</a></a>
Moved my answer from comments"
$this->paymentdetails->delete($paymentdetail->id);
seems over-engineered and confusing
$paymentdetail is instance of Paymentdetail and it extends Laravel Model. As it is instance of model - it knows how to find itself in DB therefore you can call
$paymentdetail->delete();
and instance will delete itself
First check your request method,it should be Get method.
iF method is Get then is it redirecting to given function?
You should on debug mod of laravel which gives you proper error.
Another thing check is user authenticated?
My view is like this :
...
<a class="btn btn-primary pull-right" style="margin-top: -10px;margin-bottom: 5px" href="{!! route('users.create.year', [$year]) !!}">
Add New
</a>
...
...
#foreach($testArray as $key)
...
<a class="btn btn-primary btn-xs" href="{!! route('users.create.year', [$key['display'], $year]) !!}">
<i class="glyphicon glyphicon-plus"></i>
</a>
...
#endforeach
...
My routes is like this :
Route::get('users/create/{year}/{display?}', 'UserController#create')
->name('users.create.year');
My controller is like this :
public function create($year, $display = null)
{
echo $display.' : display <br>';
echo $param_thang. ' : year';die();
...
}
When I call url like this : http://localhost/mysystem/public/users/create/2016, it works.
There result is like this :
: display
2016 : year
When I call url like this : http://localhost/mysystem/public/users/create/14144499452111901/2016
The result is like this :
2016 : display
14144499452111901 : year
It looks strange, the result is reversed
Why did it happen?
It's because your route is:
Route::get('users/create/{year}/{display?}', 'UserController#create')
->name('users.create.year');
So the first parameter is always going to be the year, and the 2nd parameter is always going to be the display variable.
You need to change your <a> as #farkie suggested:
<a class="btn btn-primary btn-xs" href="{!! route('users.create.year', [$year,$key['display']]) !!}">
<i class="glyphicon glyphicon-plus"></i>
</a>
I defined a resource in my routes like this:
Route::resource('shops', 'shopsController');
I need to create a link to delete an item
<a class="btn btn-xs btn-danger" href="{{ URL::to('shops/'. $row->id . '/destroy') }}" > </a>
but this URL requires me to define a new route like this:
Route::get('shops/{id}/destroy', 'shopsController#destroy');
So, how can I enforce the URL to go through the default route, through its resource, to get the destroy function??
I tried
href="{{ route('shops.destroy', $row->id ) }}" data-method="delete"
but I redirects me to show() instead!!!!
You can't delete the user via anchor tag href attr you need to delete it either with form or use Ajax.
{{ Form::open(array('url' => 'shops/'. $row->id)) }}
{{ Form::hidden('_method', 'DELETE') }}
{{ Form::submit('Delete this User', array('class' => 'btn btn-warning')) }}
{{ Form::close() }}
Here's the
similar question
Update
Hope this would help you.
You can pass $row->id to the anchor Id attr like so
<a class="btn btn-xs btn-danger" id="{{$row->Id}}" onclick="delete_user(this.id) return false;" href="#" rel="nofollow" >Delete this entry</a>
and then use the below script to work with Destory method.
function delete_user(Id) {
var result = confirm("Want to delete?");
if (result==true) {
$.ajax({
url:'http://localhost:81/laravel/myapps/public/shops/'+Id,
type:"Post",
data: {'_method':'delete'},
success:function($msg){
alert($msg);
}
});
}
}
</script>
Try this
<a class="btn btn-xs btn-danger" href="{{ route('shops.destroy',array($row->id)) }}" data-method="delete" rel="nofollow" data-confirm="Are you sure you want to delete this?">Delete this entry</a>
laravel-delete
I'm trying to use two params with a named route through a controller, but receive an error when loading the view
Route
Route::get('agendarVehiculo/{idvehiculo}/{idcita}', array('as' => 'agendarVehiculo', 'uses' => 'AgendamientosController#addAgendaCitaVehiculo'));
View
<td>
<i class="fa fa-calendar"> Agendar</i>
</td>
Error
syntax error, unexpected '['
Any idea would be greatly appreciated Thanks!
Is your PHP 5.4+? If not, you'll have to:
<td>
<a href="{{ route('agendarCitaPaciente', array($paciente->id, $cita->id)) }}" class="btn btn-xs btn-success">
<i class="fa fa-calendar"> Agendar</i>
</a>
</td>
As pointed by #SumanBogati, you also have a missing parenthesis.
Try changing
[$paciente->id, $cita->id ]
To
array($paciente->id, $cita->id)
It looks like you're using a PHP version that doesn't support the newer method of defining arrays.
You may forgot to write colosing parenthesis ) on this
<i class="fa fa-calendar"> Agendar</i>
//--------------------------------------missing parenthesis here----^
I have a link that looks like this:
<a class="btn btn-primary edit"
href="Personas/details/<?php echo $persona['Persona']['id']; ?>"
data-original-title="Editar">
<i class="icon-pencil icon-white"></i>
</a>
As you can see I'm manually writing in the controller and action for the link. Is there some way to make this not as brittle?
Something like:
<a href="Url.Action("Personas", "Details", array('id', 1);" >Asdf</a>
Use: Html->url, does exactly what you want.