Reputation: 429
I am trying to pass my data to my home.blade.php but I keep getting a error called "Use of undefined constant data1 - assumed 'data1'
" I have double checked my code but still don't know what to do, my names seem to be able to be shown out in the view but not the hire status. Can someone help me thanks a lot
Home.blade.php
<table class="table table-bordered">
<tr>
<th><strong><big>Name: </big></strong></th>
<th><strong><big>Hire Status: </big></strong></th>
</tr>
<td>
<tr>
@foreach($data as $value)
<tr>
<th><a href="{{route('user.show',['id'=>$value->id])}}">{{$value->Name}}</a></th>
<th>
@foreach(data1 as $value1)
{{$value1->hire_status}}
</th>
</tr>
@endforeach
@endforeach
</tr>
</tr>
</table>
HireController:
public function hire_view(){
$data1['data1'] = DB::table('hires')->where('hire_status',Yes)->get();
if($data1 = "Yes"){
return view('home')->with(compact('data1'));
}else{
return view('home')
}
}
HomeController:
public function getData(){
$data['data'] = DB::table('personal_infos')->where('deleted_at',NULL)->get()->sortByDesc('created_at');
if(count($data)>0){
return view('home',$data);
}else{
return view('home');
}
Upvotes: 1
Views: 83
Reputation: 243
if($data1 = "Yes"){
return view('home',$data);
}else{
return view('home')
}
Upvotes: 0
Reputation: 15529
In the 4th line of this piece of code
if($data1 = "Yes"){
return view('home')->with(compact('data1'));
} else {
return view('home')
}
if data1
is not "Yes" you don't pass the data1 variable to the view, and then the view can not access it.
Oh my god, just realized you are using "=" in the comparison instead of "==".
Upvotes: 0
Reputation: 1301
You can pass your data in view file by two way like, 1st one is
$data1 = DB::table('hires')->where('hire_status',Yes)->get();
return view('home',compact('data1'));
or,
$data1 = DB::table('hires')->where('hire_status',Yes)->get();
return view('home')->with('data1',$data1);
and you have forgot the $ sign here,
@foreach(data1 as $value1) // "$" sign before data array variable.
I hope it helps.
Upvotes: 2
Reputation: 43
Try changing
@foreach(data1 as $value1)
in home.blade.php to
@foreach($data1 as $value1)
you simply forgot the $ there, so the code treats "data1" as a constant instead of a variable
Upvotes: 1