V
V
Valery Khizhevsky2017-07-20 21:19:54
Laravel
Valery Khizhevsky, 2017-07-20 21:19:54

Why does it not see the variable in foreach?

Laravel throws this error:
Undefined variable: Tasks;

public function find(Request $request){
    	$post_data = $request->all();
    	$name_user = $post_data['name-user'];
    	$tasks = Task::where('creator',$name_user)->get();
    	foreach($Tasks as $task):
    		echo $task;
    	endforeach;
    }

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Artem0071, 2017-07-20
@Roshette

because you are writing to $tasks, not to $Tasks
Look carefully at the registers

E
Eugene Mosyukov, 2017-07-20
@GeneMoss

The register. You have declared the $tasks variable, but you are accessing a non-existent $Tasks.

D
Dave, 2017-07-20
@djay

foreach($Tasks as $task):
Not $Tasks a $tasks

V
Vladimir, 2017-07-20
@djQuery

$tasks
foreach( $Tasks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question