Reputation: 146
I have created a database and i can't able to access it. when on link on the link it is displaying a blank page. No errors. how can i view the page. with the below contents. i need to access only few columns from database.
Content
<table >
<tr>
<th><input type="checkbox"name="check" id="tes5" class="checkall"></th>
<th>Company Name</th>
<th>First Name</th>
<th>Last Name</th>
<th>Priority</th>
<th>Lead Status</th>
<th>Country</th>
</tr>
@foreach ($users as $user) {
<tr>
<td><input type="checkbox"name="check" id="tes5" class="checkall"></td>
<td>{{ $user->cname }}</td>
<td>{{ $user->fname }}</td>
<td>{{ $user->lname }}</td>
<td>{{ $user->priority }}</td>
<td>{{ $user->leadsta }}</td>
<td>{{ $user->country }}</td>
</tr>
@endforeach
</table>
Controler
public function leadlist(){
$users = DB::table('leadlist')->select([
"cname"=>$_GET["cname"],
"fname"=>$_GET["fname"],
"lname"=>$_GET["lname"],
"priority"=>$_GET["priority"],
"leadsta"=>$_GET["leadsta"],
"country"=>$_GET["country"],
]);
return view('forms.leads.list');
}
Route
Route::get('leadslist', 'crmcontroller@leadlist');
Upvotes: 1
Views: 323
Reputation: 70
by using select you can't retrive the data u should use get()
to retrieve the data.
public function leadlist(){
$users = DB::table('leadlist')->get();
return view('forms.leads.list')->with('users',$users); }
so we are using with('users',$users)
because it helps in view to retrieve data
Upvotes: 0
Reputation: 445
I think by mistake you are passing parameter.
Also you are not passing users to the view.
Please try this code in Controller:
public function leadlist(){
$users = DB::table('leadlist')-> get();
return view('forms.leads.list',compact('users'));
}
compact('users')
is used to pass $users
to view. Here is the link for more details on compact()
Upvotes: 0
Reputation: 8078
You have not pass $users object to view
return view('forms.leads.list',['users'=>$users]);
Also you need to use get()
$users = DB::table('leadlist')->select([
cname,
fname,
lname,
priority,
leadsta,
country,
])->get();
You can read more about select here https://laravel.com/docs/5.5/queries#selects
Specifying A Select Clause
Of course, you may not always want to select all columns from a database table. Using the select method, you can specify a custom select clause for the query:
$users = DB::table('users')->select('name', 'email as user_email')->get();
Upvotes: 0
Reputation: 26258
There are two issue with your code:
$users = DB::table('leadlist')->select([
"cname"=>$_GET["cname"],
"fname"=>$_GET["fname"],
"lname"=>$_GET["lname"],
"priority"=>$_GET["priority"],
"leadsta"=>$_GET["leadsta"],
"country"=>$_GET["country"],
]);
here, you are using select()
in wrong way.
Specifying A Select Clause
Of course, you may not always want to select all columns from a database table. Using the select method, you can specify a custom select clause for the query:
$users = DB::table('users')->select('name', 'email as user_email')->get();
So their is no meaning of passing that $_GET["cname"]
in select()
, specify only column name.
And, you have to pass the object to the view like:
return view('forms.leads.list',['users'=>$users]);
only then users
is available on the view.
Upvotes: 2