Reputation: 47
public function index($id)
{
if($id == NULL){ // when $id value missing then redirect
return redirect('service');
}else{
// some operation perform
}
I want to perform some action on id value when id value missing user redirect
to service page,value coming from get method here please help me ,this is not working
Upvotes: 2
Views: 81
Reputation: 23978
Add a default value NULL
for $id
in function definition itself.
If the function does not get any value, it will NULL
Check if the function is getting blank $id
by using empty() function.
This way, your functionality of redirection will work properly.
Also, your warning will get removed.
public function index($id = NULL) {
if (empty($id)) { // when $id value missing then redirect
return redirect('service');
}
else {
// some operation perform
}
}
Upvotes: 2
Reputation: 1438
Change your function as below:
public function index($id = '') {
if(empty($id)){
return redirect('service');
}else{
// perform operation
}
}
Upvotes: 1
Reputation: 4128
Change your function as below:
public function index($id = '') {
if(!trim($id)){ // when $id value missing then redirect
return redirect('service');
}else{
// some operation perform
}
}
Upvotes: 1
Reputation: 8441
You have to tell in your arguments the null value
public function index($id = null)
If no value, $id = null. So you can redirect easily.
Upvotes: 4