Postingan lainnya
Error Call to a member function count() on string Cara ngatasinnya gimana ea
Pas lagi ngebuat metode searching udh ngeliat tutorialnya masih kagak bisa udh gagal paham walau nyari di google http://imageshack.com/a/img922/4046/hCUZcg.jpg http://imageshack.com/a/img924/3006/dnL4p7.jpg http://imageshack.com/a/img922/2906/khnKZk.jpg
<?php
namespace App\Http\Controllers;
use DB;
use App\Models\User;
use Illuminate\Http\Request;
class SearchController extends Controller
{
public function getResults(Request $Request)
{
$query = $Request->input('query');
if (!$query){
return redirect()->route('home');
}
$users = User::where(DB::raw("CONCAT(first_name, ' ', last_name)"),
'LIKE', "%{$query}%")
->orWhere('username', 'LIKE', "%{$query}%")
->get();
return \View::make('search/result')->with('users', '$users');
}
}
@extends('templates.default')
@section('content')
<h3>Your Result is"{{ Request::input('query') }}"</h3>
@if ( !$users->count() )
<p>No Result Found</p>
@else
<div class="row">
<div class="col-lg-12">
@foreach ($users as $user)
@include('user/partials/userblock')
@endforeach
</div>
</div>
@endif
@stop
0
7 Jawaban:
coba scriptnya di post di sini aja mas.. biar enak keliatannyaa.. :)
0
<?php
namespace App\Http\Controllers;
use DB;
use App\Models\User;
use Illuminate\Http\Request;
class SearchController extends Controller
{
public function getResults(Request $Request)
{
$query = $Request->input('query');
if (!$query){
return redirect()->route('home');
}
$users = User::where(DB::raw("CONCAT(first_name, ' ', last_name)"),
'LIKE', "%{$query}%")
->orWhere('username', 'LIKE', "%{$query}%")
->get();
return \View::make('search/result')->with('users', '$users');
}
}
0
Jawaban Terpilih
coba bagian
....
@if ( !$users->count() )
<p>No Result Found</p>
....
ubah ke
@if ( count($users) == 0 )
<p>No Result Found</p>
0
ErrorException in 02fc26e581969aaf89bc92cb727a0871 line 12: Invalid argument supplied for foreach() (View: C:\xampp\htdocs\potato\resources\views\search\result.blade.php)
<?php
namespace App\Http\Controllers;
use DB;
use App\Models\User;
use Illuminate\Http\Request;
class SearchController extends Controller
{
public function getResults(Request $Request)
{
$query = $Request->input('query');
if (!$query){
return redirect()->route('home');
}
$users = User::where(DB::raw("CONCAT(first_name, ' ', last_name)"),
'LIKE', "%{$query}%")
->orWhere('username', 'LIKE', "%{$query}%")
->get();
return \View::make('search/result')->with('users', '$users');
}
}
1
$users itu datanya array apa string? Di errornya dia menghitung string soalnya, jadi nggak bisa. Pastikan dulu kalau datanya array.
die(var_dump($users));
// Dan coba ini diganti
return \View::make('search/result')->with('users', '$users');
// Jadi gini
return \View::make('search/result')->with('users', $users);
1